Finding Lowest score from a txt file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
ifstream gradeFile;
gradeFile.open("ScoreData.txt");
if(gradeFile.fail())
{
cout << "File not found. Program terminated." << endl;
return 1;
}
char initial1; // initial one
char initial2; // initial two
int score; // student's test scores
int numscores = 0;
int sum = 0;
float average;
int s = 1;
int lowestscore = 0;
int M = 20;
cout << "Name ";
for(s; s <= 10; s++)
cout << left << setw(5) << s;
cout << left << setw(5) << "Low";
cout << left << setw(5) << "Avg";
while(!gradeFile.eof())
{
gradeFile >> initial1 >> initial2;
cout << "\n" << initial1 << "." << initial2 << ". ";
do
{
gradeFile >> score;
if(score != -1)
{
cout << left << setw(5) << score;
sum += score;
numscores++;
}
}
while(score != -1);
average = (float) (sum - lowestscore) / numscores;
cout << left << setw(5) << fixed << setprecision(1) << average;
}
//for(
gradeFile.close();
cout << "\nAll Student Processed." << endl;
return 0;
}
|
I'm having trouble taking out the lowest score from each row and placing it in the right spot on the display.
Name 1 2 3 4 5 6 7 8 9 10 Low Avg
A.A. 5 11 9 5 8 5 3 3 7.2
R.D. 11 2 3 12 8 11 9 2 9.0
J.E. 10 N/A 10.0
K.H. 4 11 5 4 6 8 2 6 11 5 2 6.7
G.M. 10 1 1 9 3 1 5.8
S.O. 3 1 6 1 4.5
|
That is how i what it to look. Right now it looks like this.
Name 1 2 3 4 5 6 7 8 9 10 Low Avg
A.A. 5 11 9 5 8 5 3 6.6
R.D. 11 2 3 12 8 11 9 7.3
J.E. 10 7.5
K.H. 4 11 5 4 6 8 2 6 11 5 7.0
G.M. 10 1 1 9 3 6.6
S.O. 3 1 6 6.3
|
As you can see i cant get the lowest score out or get the avg or low scores in the right places. Any help would be great Thank You.
Topic archived. No new replies allowed.