Hi! I have a last minute assignment to create a program that converts the input of a number of student grade scores into letter grades and store it in an array with;
string courses [5] = {physics, math... etc} and
int score[5];
string grade [5];
And then prints it out.
I've been coding for 11h straight and my brain isnt really doing much for me right now haha, so Id be super grateful for some advice on how to go about it to get rolling! ^^
Use the principle of parallel arrays and combine that with a cin for the score each time and then process that score with an if - else if - else cascade
If you bwant to be very efficient and the grades are single characters rather that A+, B- etc then grade[] can be char rather than string.
Of course the immediate start is #include, int main() stuff.
Thanks, how do i properly prompt cin for score though?
when I do; std::cout << "Enter mathematics score:";
std::cin >> score;
I get a error message. :/
Haha ops copy pasted it, had already changed it actually didnt see it was wrong nrs sorry! Thank you! :P
Does anyone have any tips of an efficient way to convert the score to grade and input it to array?
: )
char CalculateGrade(const int gScore)
char grade;
if (gScore > 95)
return 'A';
else if (gScore > 90)
return 'B';
else if (gScore > 80)
return 'C';
else if (gScore > 70)
return 'D';
else if (gScore > 60)
return 'E';
else
return 'F';
}
gScore was not declared~. Sorry for the dumb questions, been awake for 20h and coding for 14h straight, just need to finish this last assignment but the hamster already fell out haha. -.-
Ahh sorry! Very hard to avoid even the simplest mistakes right now. :P
This is what it looks like now but im getting the error 'a function definition is not allowed here before { token on line 30.
Also how do I get my CalculateGrade function to store the converted input data in the array?
Thanks so much for your help, pardon the stupid questions but can barely keep my eyes open haha.
Does it work Proper? The if cascade I mean. There are many ways to do it and if you have tested it thoroughly then give it a tick. If I get a chance I'll try it myself but I doubt whether I can 'break' it. :)
I'm a bit worried about that 100 previously. Just make sure you only have to deal with one student.
grade[index] = CalculateGrade( score[index] ) sounds good to me.
Check it out :)
BTW Depending on your decision with returns. If you use return 'A' etc then char grade is not used and that line can be deleted. Or you can say grade = 'A' etc and return grade at the end. Probably a bit more efficient the 1st way but it is a 50/50 decision, especially with just one student.