Hi all,
I just started a C++ class and have figured out that I can't quit my day job! I have a simple problem - figure out the average, minimum, and maximum numbers for a list of numbers that I enter with -1 to end the listing.
I have been struggling for 3 days on how to get the min & max numbers. I have tried a few diferent things, but I just can't think it out in my head in a logical code way!
Now I can't even get the average to work - it WAS working before I started in again trying to do the min & max.
Any assistance would be greatly appreciated. I don't want anyone to do it for me, but an explanation of how I can accomplish this would be great! The code I have altered at least 50 times is below.
thanks mz
Code:
//"This program calculates the average score, minimum score and maximum score."
#include <iostream.h>
void main()
{ float tscore=0.0, sumscore = 0.0, count = 0.0, average;
// int minscore, maxscore;
cout <<"Enter a list of positive values (ending with -1):";
cin >> tscore;
// for (maxscore=minscore=tscore; tscore > -1;); {
// if (tscore < minscore)
// minscore = tscore;
// else if (tscore > maxscore)
// maxscore = tscore; }
while (tscore > 0.0)
sumscore = sumscore + tscore;
count = count + 1;
cin >> tscore;
average = sumscore / count;
cout << "The average is :" <<average << endl;
// cout << "The minimum score is :" <<minscore << endl;
// cout << "The maximum score is :" <<maxscore << endl;
}
PS It is always good to try new things, if for nothing else, to see how some things just aren't for you.