Hi, all. I'm working on another homework assignment, and once again, I'm having a bit of trouble. I've searched the web quite extensively and everywhere I look, the answer always seems to be to use a vector, however, my professor specifically instructed us to use an array. My assignment is as follows :
#7.12 (Assigning grades) Write a program that reads
student scores, gets the best score, and then assigns
grades based on the following scheme:
Grade is A if score is >= best – 10;
Grade is B if score is >= best – 20;
Grade is C if score is >= best – 30;
Grade is D if score is >= best – 40;
Grade is F otherwise.
The program prompts the user to enter the total number of
students, then prompts the user to enter all the scores,
and concludes by displaying the grades. Here is a sample
Run:
Enter the number of students: 4 [enter]
Enter 4 scores: 40 55 70 58 [enter]
Student 0 score is 40 grade is C
Student 1 score is 55 grade is B
Student 2 score is 70 grade is A
Student 3 score is 58 grade is B
I've created an array, with a size of 25 ( just a random number I've selected ) and I think I've successfully written the code to populate the array, and to determine the max, however the actual printing of the statements is where I'm stuck. No matter what, the outcome always seems to be 'D'. Any help is greatly appreciated !!
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
|
#include <iostream>
using namespace std;
int main()
{
char grade;
int students, score;
int studentSCORES[25];
cout << "Enter the number of students: ";
cin >> students;
cout << "Enter " << students << " scores: ";
for (int i = 0; i < students; i++)
{
cin >> score;
}
double max = studentSCORES[0];
for (int j = 0; j < students; j++)
{
if (studentSCORES[j] > max) max = studentSCORES[j];
}
for (int k = 0; k < students; k++)
{
if (studentSCORES[k] >= max - 10)
grade='A';
else if (studentSCORES[k] >= max - 20)
grade='B';
else if (studentSCORES[k] >= max - 30)
grade='C';
else if (studentSCORES[k] >= max - 40)
grade='D';
else grade='F';
for (int i=0; i <= students; i++)
{
cout << "Student " << i << " has score " << score << " and grade " << grade << ".";
}
return 0;
}
}
|