#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
void main()
{
string dataFile("ExamScores.txt");
ifstream fin;
fin.open(dataFile);
int s(0), ns(0), sns(0);
int total_score(0);
int max = s;
int min = s;
fin >> s;
while( ! fin.eof() )
{
++ns;
total_score += s;
if(s > max)
{
max = s;
}
if(s < min)
{
min = s;
}
fin >> s;
}//end file read loop
cout << total_score/ns << endl;
cout << "Max: " << max << endl;
cout << "Min: " << min << endl;
fin.close();
}
And here is my output when I run the program.
75
Max: 90
Min: 0
Press any key to continue . . .
I am reading from a file in this program which contains a set of 30 numbers and it has the average correct and the max correct but the minimum number in the set is 56 however it keeps giving me a zero for the min. Any help is appreciated.
I actually did that afterwards. I initialized it to 56 because it's the only reason I could think of why I keep getting zero although I'm not sure if that's proper programming but it's all I've got for now. Thanks for the help!
well, if the highest realistic exam score is 100, you could initialise 'min' to 100. i.e. the maximum value your 'min' variable could ever be. If that makes sense? :)