I am writing a program and stuck on entering standard deviation. I have looked on previous forum topics and from what I have found this is what I have coded but when I cout my standard deviation I keep getting a 1.#f Can one of you guys take a look and show me what I need to change....

#include <iostream>
#include <cmath>
using namespace std;

//Display functions
void calculateMean(double, double);
void calculateStandardDeviation(double, double, double);
void getLetterGrade();

//enter main function
int main()
{
	//Declare variables
	double count;
	double score, totalScores = 0.0, mean = 0.0;

	//ask user how many scores user wishes to enter
	cout << "How many scores do you wish to enter? ";
	cin >> count;

	//for loop statement to enter all the scores from the amount the user wishes to enter
	for (double num = 1.0; num <= count; num++)
	{
		cout << "Enter score " << num << ": ";
		cin >> score;

		//Calculate the total of the scores
		totalScores = totalScores + score;
	}

		//Function to calculateMean()
		calculateMean(count, totalScores);

		//Function to calculateStandardDeviation()
		calculateStandardDeviation(count, mean, totalScores);

	

	//Function to getLetterGrade()
	getLetterGrade();

	//return a value
	return 0;
}

//calculate Mean function
void calculateMean(double numberScores, double totalScores)
{
	//Declare variables
	double mean;

	//Calculate the mean
	mean = (1.0 / numberScores) * totalScores;

	//Display the mean
	cout << "The mean of the scores is " << mean << endl;
}

//calculateStandardDeviation() function
void calculateStandardDeviation(double mean, double count, double totalScores)
{
	//Declare variables
	double standardDeviation;

	//Calculate the standard Deviation
	standardDeviation = sqrt (((pow(totalScores, 2.0)) - ((1.0/count) * (pow(totalScores,2.0)))) / (count - 1.0));
	

	cout << "The standard deviation of the scores is " << standardDeviation << endl;

}

//Determine the letterGrade() function
void getLetterGrade()
{



}

>> I keep getting a 1.#f
That means it is a very large or very small number. Add fixed to the cout line and cout will display it correctly cout << fixed << 0.000001 << '\n';

this is probably going to make me look like an idiot but I tried in two places and I now get the following output....

1.IINF00

Here is my code

void calculateStandardDeviation(double mean, double count, double totalScores)
{
	//Declare variables
	double standardDeviation;

	//Calculate the standard Deviation
	cout << fixed;
	standardDeviation = sqrt (((pow(totalScores, 2.0)) - ((1.0/count) * (pow(totalScores,2.0)))) / (count - 1.0));
	

	cout << fixed << "The standard deviation of the scores is " << standardDeviation << endl;

}

What are the values of the parameters? Perhaps they are wrong.

I really dont follow what do u mean values of the pareameters if u r asking what I put in for scores it is only like 2 scores and they are like 20, 30, etc nothign large...sorry as far asprogramming goes I still almost need lamens terms

What I mean is what values are you passing for double mean, double count, double totalScores ? If you don't know what they are then just print their values on the screen so that you can read them and post them here.

Two scores will not get you much for standard deviation, and most likely why you are having the problems you report. Suggest you create a file that contains 50 or more scores then have your program read them and make the computations.

Or if you don't what to do that, you can have your program generate 50 or so randm numbers so that you don't have to type them in every time you run your program.

ok I apologize for that sir here is what I have...Ill add the entire code too...
and by the way just disregard the getLetterGrade function for now...I am still working on that

#include <iostream>
#include <cmath>
using namespace std;

//Display functions
void calculateMean(double, double);
void calculateStandardDeviation(double, double, double);
void getLetterGrade(double, double, double);

//enter main function
int main()
{
	//Declare variables
	double score, count, totalScores = 0.0, mean = 0.0, standardDeviation = 0.0;

	//ask user how many scores user wishes to enter
	cout << "How many scores do you wish to enter? ";
	cin >> count;

	//for loop statement to enter all the scores from the amount the user wishes to enter
	for (double num = 1.0; num <= count; num++)
	{
		cout << "Enter score " << num << ": ";
		cin >> score;

		//Calculate the total of the scores
		totalScores = totalScores + score;
	}

		//Function to calculateMean()
		calculateMean(count, totalScores);

		//Function to calculateStandardDeviation()
		calculateStandardDeviation(count, mean, totalScores);

	

	//Function to getLetterGrade()
	getLetterGrade(mean, standardDeviation, score);

	//return a value
	return 0;
}

//calculate Mean function
void calculateMean(double numberScores, double totalScores)
{
	//Declare variables
	double mean;

	//Calculate the mean
	mean = (1.0 / numberScores) * totalScores;

	//Display the mean
	cout << "The mean of the scores is " << mean << endl;
}

//calculateStandardDeviation() function
void calculateStandardDeviation(double mean, double count, double totalScores)
{
	//Declare variables
	double standardDeviation;

	//Calculate the standard Deviation
	cout << fixed;
	standardDeviation = sqrt (((pow(totalScores, 2.0)) - ((1.0/count) * (pow(totalScores,2.0)))) / (count - 1.0));
	

	cout << fixed << "The standard deviation of the scores is " << standardDeviation << endl;

}

//Determine the letterGrade() function
void getLetterGrade(double mean, double standardDeviation, double score)
{

	if (mean + (3/2 * standardDeviation) <= score)
	{
		cout << "This score is an A.";
	}

	else if (mean + (1/2 * standardDeviation) <= score < mean + (3/2 * standardDeviation))
	{
		cout << "This score is a B.";
	}

	else if (mean - (1/2 * standardDeviation) <= score < mean + (1/2 * standardDeviation))
	{
		cout << "This score is a C.";
	}

	else if (mean - (3/2 * standardDeviation) <= score < mean - (1/2 * standardDeviation))
	{
		cout << "Score is a D.";
	}

	else if (score < mean - (3/2 * standardDeviation))
	{
		cout << "Score is a F.";
	}
	else
	{
		cout << "Score is incomplete.";
	}
}

Here is what I have passing...
count - the total numbers of scores I am entering so it will vary
mean - it is from the mean function and it just the total of all the scores vided my the count so it will vary
totaScores- this adds up the scores so it will vary

According to this wiki article your sd function needs to do more work.

First you will need an array to hold all the scores until after the mean is calculated.

Next you need to change the function calculateMean() to return the mean value so that main() can use it. As it is, the value of mean is 0 in main() even though it's calculated in that function. main() knows nothing about the value of mean in calculateMean().

After calculate mean, you need to calculate the sum of the difference between each value and the mean. That's where you need the array that contains the original scores.

>>Here is what I have passing...
>>count - the total numbers of scores I am entering so it will vary
>>mean - it is from the mean function and it just the total of all the scores >>vided my the count so it will vary
>>totaScores- this adds up the scores so it will vary

Yes I know that -- what I am looking for are numbers, not explanation.

standardDeviation = sqrt (((pow(totalScores, 2.0)) - ((1.0/count) * (pow(totalScores,2.0)))) / (count - 1.0));

Look at the formula. See if it's correct. If you don't understand the standard deviation formula, stop and do a few by hand. Whenever a compound formula goes wrong, you need to split the compound formula into its parts. You have way too much going on in that formula in a single line and no way to display its parts. Break it up. Look up the formula online and make sure that what you have here fits it. You have at least two possibilities:

  1. Bad data to the fomula.
  2. Bad formula.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.