C++ :: Unable To Compute Standard Deviation?
Mar 15, 2014Unable to compute Standard Deviation
View 1 RepliesUnable to compute Standard Deviation
View 1 RepliesI have to write a program in which it is to compute the mean and standard deviation from a set of 10 random scores between 1 and 20. The C++ program should generate a set of scores randomly and then, compute the mean and standard deviation from such a set of scores.
View 2 Replies View RelatedI've been trying to calculate the Second standard deviation but the average in the second loop isn't calculating correctly which is causing the standard deviation (method 2) to not calculate correctly. I can't find anything wrong.
Code:
#include <iostream>#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
usingnamespacestd;
int main ()
[Code]...
I have a program that will calculate max, average, etc from a file of numbers. However, I cannot get it to calculate standard deviation.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
[code]....
Here's my attempt:
input.open(name);
if (input.fail()){
cout <<"Error opening file"<<endl;
}
while (input>>numbers)
{
counter++;
total += numbers;
[Code]...
Copy of the output:
Error opening file
The Standard Deviation of all the numbers is: -9.25596e+061
Press any key to continue . . .
Its not giving me the right answer.
The program does compile the average and the mean correctly. I can't understand why the standard_deviation member function isn't applying the sqrt properly:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const int N = 10;
class Standard_Deviation {
[Code] ....
I've been trying to calculate the Second standard deviation but the average in the second loop isn't calculating correctly which is causing the standard deviation (method 2) to not calculate correctly.
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;
int main () {
cout << "
This program will produce statistics (Mean, Standard Deviation, "
[code]...
How to write a formula for standard deviation but im having a hard time ?
View 2 Replies View RelatedThe values in my file are 5,5,332,156,11,0,555,32,8,9 .... the computer when I scan and read is missing the first 5 and only showing 9 values which is messing up my mean and standard deviation. But when I have them put in order all of my numbers show up:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SIZE 100
void bubbleSort( int * const array, size_t size);// prototype
[Code] .....
if possible, why won't the median work. I have it commented off as of right now....
A Bookseller makes special discount for multiple orders of a book as follows:
AMOUNT and DISCOUNT as follows.
5-9 5% 10-14 10% 15-19 15% 20+ 20%
Write a C main function to read the amount of order from the standard input and compute and print the total price of the given order after the discount. Assume that unit price of a book is 10.00$
My problem is that.When i start with this
Code:
#include<stdio.h>
#include <stdlib.h>
int main(void)
{
int number;
float TotalPrice;
printf("enter a number:");
[Code] ....
I get 0 if i enter a number between 0 and 4(0 and 4 included). I don't know where I am doing a mistake. I also want to know if i can handle this buy just if statements. or how can i do it by while and for loops ?
This program is supposed to find the value of a polynomial
with x being the number of terms
a[x] being the coefficients
b[x] being the exponents in each term
j being the variable
for example if
x=4
a[x]=1,2,1,5
b[x]=3,2,1,0
j=2
then the polynomial is (j*j*j)+2(j*j)+j+5
the value will be 23
however the value computed is wrong in the code below
#include <stdio.h>
#include <math.h>
int main()
[Code].....
I intended to compute perimeter of a triangle. The problem is the initial value for the triangle.
#include <iostream>
#include <cmath>
using namespace std;
struct Point{
double x;
double y;
[Code] ......
I expect to get 0 for triangle1, but I get some strange value...
Here is the result
Type x for point1 : 1
Type y for point1 : 1
Type x for point2 : 3
Type y for point2 : 1
Type x for point3 : 1
Type y for point3 : 3
The perimeter of the triangle1 is : 2.82843
The perimeter of the triangle2 is : 6.82843
I am trying to do a compute and output a power set program. The numbers will be input through a file. How to do a power set. Here is my code :
#include <iostream>
#include <fstream>
#include <string>
#include <ostream>
using namespace std;
int main () {
string array[21]; // creates array to hold names
[Code] .....
I am writing code, which reads an input file (280 MB) containing a list of words. I would like to compute
1) total # of words
2) total # of unique/distinct words
3) mean/median/mode of word count (Link)
I managed to get done with 1) and 2), but my program crashes for 3). I am not quite sure whether there are memory issues or some bug in the code.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
[Code] .....
How would I make a loop that would simultaneously compute both the max and min of a vector?
View 2 Replies View RelatedHow can you draw a flow chart that will be used to write a program to compute Average of n numbers?
View 1 Replies View RelatedGiven a structure book defined as follows and an array lib of books
Code:
struct Book{
char title[100];
char author[100];
int price;
struct Book *nextedition;
};
struct Book lib[1000]; I'm going to write a function to compute total price of books by a given author including all books which are future editions of his book, even if the author of that future edition is NOT the specified author. title author price nextedition Book1 Author1 25 &lib[2] Book2 Author2 20 NULL Book3 Author3 30 &lib[3] Book4 Author1 35 NULL
For the example above, given the author "Author1", the function should return 90 (=25+30+35), and given the author "Author 3", the function should return 65 (=30+35).
So here's my attempt:
Code:
int totalPrice(char author[100]){
int total=0;
for (i=0; i<numbooks; i++)
if(strcmp(author, lib[i].author==0))
[Code] ....
What I'm trying to do is finding the first book in the lib of the specified author using for loop and then let the while loop do the rest. However, it seems the price is over-counted after each iteration of the for loop but I don't know how to fix it.
I have to write some cpp program which computes area of a triangle using cross product,we give 3 vertices as R2 and 3 edges as double.
I am beginning like this;
#include <iostream>
#include "R2.h"
#include <cmath>
using namespace std;
double area ( R2 *A,double *z)
[Code] .....
How to compute financial ratio in C++ with using header file?
Calculate in c++ program with 3 different file. - 2 file (cpp file) - 1 file (header file)
Information:
formula:-
*1.*Current ratio = (current asset / current liabilities)
*2.*Gross margin = (Revenue – Cost of goods sold) / Revenue
*3.*Operating margin= (Operating Income / Revenue)
*4.*Profit margin = (Net Profit / Revenue)
*5.*ROE= (Net Income/Shareholder's Equity)
I want put 5 formula to run the program. How to put 5 formula in the program but run one formula.
EXAMPLE: In the coding, write all financial ratio. When we compile, just asking 1 formula value only. We need to fixed, which formula to run. Just adjust the coding only.
Write a program that uses a function to compute the cost of a pizza with given diameter and the number of toppings. Constant will be the cost per toppings and cost per square inch. It will contain a reputable structure as well.
diameter=17
number of toppings=3
//complier directives
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
[Code].....
I got an assignment which asked me to create a program that asks user to input 10 numbers (positive and negative) integer. The program would be using loop to compute sum and average of all positive integers, the sum and average of negative numbers and the sum and average of all the number entered. But, the new problem is after I've entered all the number, the answer that the program gave me wasn't the answer that the program supposed to give. I don't know how to describe it, I would attach a picture and the code below:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
//Declaration
int x, value, sum, average, SumPositive, SumNegative, Positive, Negative;
float AveragePositive, AverageNegative;
[Code] .....
The program will ask for the user to enter a value for x, then compute the following polynomial: 3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6.However, when I double check it with my calculator I get a wrong answer for random values of x. To simplify my problem I'm using only integers.
Code:
#include <stdio.h>
int main(void)
{
int x, polynomial;
}
[code]...
This is my program, for now it is intended to compute permutations of any string entered, but the function ox will not return the final x value. ox is the function that actually computes the permutations so the return of the x value is critical.
Code:
#include<stdio.h>
#include<string.h>
int ox(int x);
int main() {
int x;
char input[10];
[Code] .....
Community Hospital needs a program to compute and print a billing statement for each patient. Charges for each day are as follows:
a. room charges: private (P) room = $125.00; semi-private (S) room = $95.00; or ward (W) = $75.00
b. telephone charge = $1.75
c. television charge = $3.50
Write a program to get data from the keyboard, compute the patient’s bill, and print an appropriate statement. Typical input (nut yours do not have to be identical to this) is the following:
How many days was the room occupied? 5
What type of room? P
Telephone used during the stay? N
Television used during the stay? Y
Keep in mind that the user needs to know that the input can be any integer number of days for the length of stay, either (P, S, or W) for the room type, and either (Y or N) for both telephone and television options.
A statement (which yours MUST be identical to) for the data given follows:
Community Hospital Patient Billing Statement
Number of days in hospital: 5
Type of room: Private
Room charge:$ 625.00
Telephone charge:$ 0.00
Television charge:$ 17.50
TOTAL DUE = $642.50
An instructor needs you to write a program that will compute the final average grades in her class. There are 5 students in the class. Each student must take 2 exams and 4 quizzes as part of their final grade. The weight of each toward the final grade is as follows:
Exam 1 – 30%
Exam 2 – 30% Quiz 1 – 10%
Quiz 2 – 10%
Quiz 3 – 10%
Quiz 4 – 10%
You must use arrays to store each students 3 digit ID number, exam scores and quiz scores. A multi-dimensional array is mandatory. Request from the user the information needed then output all of the information as well as the final average grade for each student.
I needed to compute average median and mode for numbers in a vector. Im having a few issues I have already figured out how to calculate average and median just not mode. Also the program crashes when 0 is entered instead of exiting nicely. Also i keep getting a error on line 47 saying primary expression expected before else.
#include <iostream>
#include <conio.h>
#include <math.h>
[Code]....