quick question, how do i get the best score, for example, after inputting 5 scores of 20, 40, 60, 80, 100, it tells me the best score is 100, before calculation of grades
In your loop from 21 to 32, you're comparing each score so far to see if it's greater than what is currently the highest score. But you set the highest score to already be 100 from the start, so the lowest that "best" can possibly be is 100. Perhaps you want to initially set "best" to be a very low number, like -1.
This will give:
Enter number of scores: 3
Enter 3 scores: 40 60 80
Student 1 score is 40 and grade is C
Student 2 score is 60 and grade is B
Student 3 score is 80 and grade is A
Enter number of scores: 5
Enter 5 scores: 20 30 40 50 60
Student 1 score is 20 and grade is F
Student 2 score is 30 and grade is F
Student 3 score is 40 and grade is F
Student 4 score is 50 and grade is F
Student 5 score is 60 and grade is C
the output i want is:
1 2 3 4 5 6 7 8
Enter number of scores: 5
Enter 5 scores: 20 30 40 50 60
The highest score is 60.
Student 1 score is 20 and grade is F
Student 2 score is 30 and grade is F
Student 3 score is 40 and grade is F
Student 4 score is 50 and grade is F
Student 5 score is 60 and grade is C
This is where "using namespace std;" can cause errors...
Rename your "max" variable to "max_score" or something like that.
(Or declare the your max variable inside the main function, instead of as a global variable.)
@Ganado has a very valid point here, a name like "max" is a bit obvious as a member of the std namespace.
However, there are times, maybe not with "max" specifically, but with other collisions which prompt that philosophy against "using namespace std;"
However, this code demonstrates a second point, and that is of not using a namespace.
If this code were in it's own namespace (which would mean this is not int main, typical of student programs), then "max" would have been inside a namespace, avoiding collision with a "using namespace std" (also, better if inside the user's namespace), such that the name isn't just max, but mns::max ( mns = my namespace), which differentiates the two from each other.
This goes to that general notion that somehow "using namespace std" is to be avoided. Many refuse, and with their own reasonable objections.
Again, though, "max" just isn't a good candidate for creating a collision with std, and there are other means of bringing the convenience of not being required to prepend "std::" in front of everything.
Ha, I didn't intend to bleed the other thread's discussion into this one. You're correct of course, there other means without having to prepend std:: onto everything.
Making the variable not global also solves it because it allows the compiler to unambiguously shadow the global identifier.
At least it isn't a #macro *cough* <windows.h> *cough*
That is not a sufficient description of a problem.
In this case the issue is that the compiler cannot compile the code, because:
In function 'int main()':
43:22: error: reference to 'max' is ambiguous
The compiler sees more than one name 'max' and cannot decide which to use. They are:
11:11: note: candidates are:
const int max
template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
In reality the compiler tends to be more verbose than that. The key point is to read what the compiler says and learn to understand the sometimes cryptic messages.
When reporting an issue it is important to show the verbatim error message. That helps others to focus on the issue. At the same time you learn to interpret the messages that your compiler writes.
Note that it is possible to explicitly refer to name that is in the global scope with prefix '::'. if (scores[i] >= ::max - 10) // ok