Click here to Skip to main content
15,906,333 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Using DrawImage(Image *, 0, 0) - Picture is too big Pin
Hamid_RT15-May-06 19:17
Hamid_RT15-May-06 19:17 
QuestionMake toolbars undockable Pin
Kleser13-May-06 4:51
Kleser13-May-06 4:51 
AnswerRe: Make toolbars undockable Pin
PJ Arends13-May-06 8:56
professionalPJ Arends13-May-06 8:56 
AnswerRe: Make toolbars undockable Pin
Hamid_RT13-May-06 9:27
Hamid_RT13-May-06 9:27 
AnswerRe: Make toolbars undockable Pin
ThatsAlok14-May-06 22:22
ThatsAlok14-May-06 22:22 
Question2 modems connection Pin
amir hossein malakouti13-May-06 2:36
amir hossein malakouti13-May-06 2:36 
AnswerRe: 2 modems connection Pin
Mohammad Tarik13-May-06 12:55
Mohammad Tarik13-May-06 12:55 
Questiontrouble with calculations Pin
lindag178313-May-06 2:30
lindag178313-May-06 2:30 
Hello
I have writen this in C++ (using the compiler Visual C++ 2005 Express Edition). I am now having some trouble with calculations. I want to work out each sample scores variance (which is used in statistics). I have a bunch of scores that hte user inputs and I can work out the average, that is the program will do that part, but when it comes to working variance the answers are wrong. The variance is worked out like this - each score minus the mean, to the power of two (or times by itself), all these scores then have to be divided by the Number of scores that are in the sample. The program cannot calculate this. For example, there are 2 scores, 1st score = 5, 2nd score = 4; it works out the mean (average) okay which is the total of all the scores divided by the number of scores in the sample. It gets very close to figuring the right amount for the variance, but not quiet. Please help me figure out where I've gone wrong. Thank You in advance. Here is my code:

#include <iostream>
using namespace std;
int main(void)

{

float M, N, total, score1, score2, score3, score4, score5, score6, score7, score8, V1, V2, V3, V4, V5, V6, V7, V8, s1, s2, s3, s4, s5, s6, s7, s8, Variance;
cout << "Input the number of people in sample ";
cin >> N;
cout << "input the 1st score ";
cin >> score1;
cout << "input the 2nd score ";
cin >> score2;
cout << "input the 3rd score ";
cin >> score3;
cout << "input the 4th score ";
cin >> score4;
cout << "input the 5th score ";
cin >> score5;
cout << "input the 6th score ";
cin >> score6;
cout << "input the 7th score ";
cin >> score7;
cout << "input the 8th score ";
cin >> score8;
total = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8;
M = total / N;
cout << "the mean for these scores is: " << M << "\n";
s1 = (float) score1 - M;
V1 = (float) s1 * s1;
s2 = (float) score2 - M;
V2 = (float) s2 * s2;
s3 = (float) score3 - M;
V3 = (float) s3 * s3;
s4 = (float) score4 - M;
V4 = (float) s4 * s4;
s5 = (float) score5 - M;
V5 = (float) s5 * s5;
s6 = (float) score6 - M;
V6 = (float) s6 * s6;
s7 = (float) score7 - M;
V7 = (float) s7 * s7;
s8 = (float) score8 - M;
V8 = (float) s8 * s8;
cout << "the variance for these scores is: " << (float) (V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8) / N << "\n";
return 0;

}


linda
AnswerRe: trouble with calculations Pin
Justin Tay13-May-06 2:56
Justin Tay13-May-06 2:56 
GeneralRe: trouble with calculations Pin
lindag178313-May-06 15:10
lindag178313-May-06 15:10 
AnswerRe: trouble with calculations Pin
Gary R. Wheeler13-May-06 3:04
Gary R. Wheeler13-May-06 3:04 
GeneralRe: trouble with calculations Pin
lindag178313-May-06 15:16
lindag178313-May-06 15:16 
GeneralRe: trouble with calculations Pin
Gary R. Wheeler14-May-06 1:27
Gary R. Wheeler14-May-06 1:27 
GeneralRe: trouble with calculations Pin
lindag178314-May-06 4:44
lindag178314-May-06 4:44 
GeneralRe: trouble with calculations Pin
Gary R. Wheeler14-May-06 6:13
Gary R. Wheeler14-May-06 6:13 
GeneralRe: trouble with calculations Pin
lindag178314-May-06 15:33
lindag178314-May-06 15:33 
GeneralRe: trouble with calculations Pin
lindag178314-May-06 15:46
lindag178314-May-06 15:46 
GeneralRe: trouble with calculations Pin
Gary R. Wheeler15-May-06 13:00
Gary R. Wheeler15-May-06 13:00 
AnswerRe: trouble with calculations Pin
Stephen Hewitt13-May-06 5:47
Stephen Hewitt13-May-06 5:47 
AnswerRe: trouble with calculations Pin
Saurabh.Garg13-May-06 16:20
Saurabh.Garg13-May-06 16:20 
GeneralRe: trouble with calculations Pin
lindag178313-May-06 21:29
lindag178313-May-06 21:29 
GeneralRe: trouble with calculations Pin
Justin Tay13-May-06 23:59
Justin Tay13-May-06 23:59 
GeneralRe: trouble with calculations Pin
lindag178314-May-06 0:46
lindag178314-May-06 0:46 
GeneralRe: trouble with calculations Pin
Saurabh.Garg14-May-06 15:04
Saurabh.Garg14-May-06 15:04 
Questionmysql database Pin
J512198213-May-06 2:13
J512198213-May-06 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.