Hello everyone. I am new to coding, taking an introductory C++ class at Baylor University. I am trying to get this standard deviation problem worked out, but I just pulled an all-nighter on it thinking it would be simple, but it is not.

I have attached the prompt for the assignment if you would care to take a look:

Assignment 1 - sum avg std dev.doc

As per the code I have developed, that can be viewed here:

/************************************************************************************************************************

Filename: Assignment 1.cpp

Author: Myles Daniel Baker

Class: CSI 1430 - 05

Description: This C++ Porgram will accept four integers from a
user, store them as variables, and prints the sum,
average, and standard deviation of the four integers.

Date Modified: 09/04/2008
- File Created
*************************************************************************************************************************/

include <iostream>
include <cmath>
include <string>

using namespace std;

int main()
{
float integer1, whole1, integer2, whole2, integer3, whole3, integer4, whole4, avg, sum, s_dev;

cout << "Hello!" <<endl;
cout << endl << endl << endl;
cout << "Using C++ we are going to evaluate the sum, average, \n";
cout << "and standard diviation of a set of four integers. \n";

cout << endl; 

cout << "Please input the 1st of 4 integers \n";
cin >> integer1;
cout << endl;
whole1 = integer1;
cout << "Integer1: " << whole1 << endl; 
cout << endl;

cout << "Please input the 2nd of 4 integers \n";
cin >> integer2;
cout << endl;
whole2 = integer2;
cout << "Integer2: " << whole2 << endl;
cout << endl;

cout << "Please input the 3rd of 4 integers \n";
cin >> integer3;
cout << endl;
whole3 = integer3;
cout << "Integer3: " << whole3 << endl;
cout << endl;

cout << "Please input the 4th of 4 integers \n";
cin >> integer4;
cout << endl;
whole4 = integer4;
cout << "Integer4: " << whole4 << endl;
cout << endl;

sum = (whole1 + whole2 + whole3 + whole4);
cout << "The sum of the four integers equals: "<< sum;
cout << endl << endl;



avg = (sum / 4);
cout << "The average of these four integers equals: " << float(avg);
cout << endl << endl;

s_dev = sqrt(-((4*avg-whole1-whole2-whole3-whole4)/4);
cout << "The standard deviation of the four integers equals: " << s_dev <<endl;

cout << endl << endl << endl << endl; 
cout <<"Thank you, have a nice day! \n";
cout << endl << endl;
return 0;

}

The professor allows us to test our programs before we submit them. He has given these values so you can compare them to yours if you run this through C++:

Int1: 23
Int2: 56
Int3: 5
Int4: 23

Sum: 107
Avg: 26.75
S_Dev: 18.417

I am wondering whether the equation he has supplied us with is correct. I am a mathematics major and cannot understand why this is so difficult for me. According to the models I have put together (the one above in addition to 5 other attempts or so) the equation should yield the correct results.

Please help!

Thanks

EDITTED

I DID figure it out but the (X-M)^2 term wasn't actually left off, it just was EXTREMELY hard to see. Oh well, sleep's overrated right?

Here is the solution in case anyone (is my class, ha ha) is having any trouble. The power of the Internet.

/************************************************************************************************************************

   Filename:                     Assignment 1.cpp

   Author:                       Myles Daniel Baker

   Class:						 CSI 1430 - 05

   Description:                  This C++ Porgram will accept four integers from a 
								 user, store them as variables, and prints the sum,
								 average, and standard deviation of the four integers.

                                                    
   Date Modified:                      09/04/2008
                -  File Created
*************************************************************************************************************************/
#include <iostream> 
#include <cmath>
#include <string>

using namespace std;

int main() 
{
	float integer1, whole1, integer2, whole2, integer3, whole3, integer4, whole4, avg, sum, a,b,c,d,s_dev;

	cout << "Hello!" <<endl;
	cout << endl << endl << endl;
	cout << "Using C++ we are going to evaluate the sum, average, \n";
	cout << "and standard diviation of a set of four integers. \n";
	
	cout << endl; 

	cout << "Please input the 1st of 4 integers \n";
	cin >> integer1;
	cout << endl;
	whole1 = integer1;
	cout << "Integer1: " << whole1 << endl; 
	cout << endl;

	cout << "Please input the 2nd of 4 integers \n";
	cin >> integer2;
	cout << endl;
	whole2 = integer2;
	cout << "Integer2: " << whole2 << endl;
	cout << endl;

	cout << "Please input the 3rd of 4 integers \n";
	cin >> integer3;
	cout << endl;
	whole3 = integer3;
	cout << "Integer3: " << whole3 << endl;
	cout << endl;

	cout << "Please input the 4th of 4 integers \n";
	cin >> integer4;
	cout << endl;
	whole4 = integer4;
	cout << "Integer4: " << whole4 << endl;
	cout << endl;

	sum = (whole1 + whole2 + whole3 + whole4);
	cout << "The sum of the four integers equals: "<< sum;
	cout << endl << endl;

	avg = (sum / 4);
	cout << "The average of these four integers equals: " << float(avg);
	cout << endl << endl;

	a = (whole1 - avg);
	b = (whole2 - avg);
	c = (whole3 - avg);
	d = (whole4 - avg);

	s_dev = sqrt((pow(a,2)+pow(b,2)+pow(c,2)+pow(d,2))/4);
	cout << "The standard deviation of the four integers equals: " << s_dev <<endl;
	
	cout << endl << endl << endl << endl; 
	cout <<"Thank you, have a nice day! \n";
	cout << endl << endl;
	return 0;
}
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.