I have an assignment and I'm stuck. The program is supposed to read in names and test scores from a data file, compute the average, and display the letter grade.
This is the code that the teacher gave us in class:
#include <iostream>
#include <cstring>
#include <iomanip>
//
// This program is designed to find the numerical score.
// and print the letter grade accordingly a student's
// name and five examination scores.
//
using namespace std;
int main()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Define all variables used in program: //
// name = name of student //
// examn = indicates exam with n being exam number //
// score = numerical score //
// letter = letter grade //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
string name;
int exam1, exam2, exam3, exam4, exam5, score;
char letter;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Read in student information until //
// end of file encountered //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
while(cin>>name)
{
cin>> exam1 >> exam2 >> exam3 >> exam4 >> exam5;
score = (exam1 + exam2 + exam3 + exam4 + exam5) / 5;
//
// Determine letter grade
//
switch(score/10)
{
case 10:
case 9: letter = 'A';
break;
case 8: letter = 'B';
break;
case 7: letter = 'C';
break;
case 6: letter = 'D';
break;
case 5:
case 4:
case 3:
case 2:
case 1: letter = 'F';
break;
}
cout << " " << setw(10) << name << " "
<< setw(4) << exam1
<< setw(4) << exam2
<< setw(4) << exam3
<< setw(4) << exam4
<< setw(4) << exam5
<< setw(6) << score
<< setw(6) << letter << endl;
//
// Get next student record
//
}
}
I'm not sure what is wrong with it, but it's not working