Trying to figure out how to do some homework and cannot figure out what operator to use to finish this program up. Tried doing some searching and experimenting but can't seem to get it. Any help would be appreciated. BTW we are not into doing arrays yet so this is supposed to be comprised of if and while statements.
Question:
Write a C++ program that prompts the user to enter the number of students, each student's score, and finally displays the highest score.
Hint: Use while loop to find the highest score.
My Code:
#include <iostream>
int main()
{
int NMBR_OF_STUDENTS = 0;
double counter = 0.0;
double grade = 0.0;
double HIGH_GRADE = 0.0;
std::cout << "How many students do you need to enter grades for? "
<< std::flush;
std::cin >> NMBR_OF_STUDENTS;
std::cout << std::endl;
while (counter < NMBR_OF_STUDENTS)
{
std::cout << "Enter grade " << counter + 1
<< " ===> " << std::flush;
std::cin >> grade;
HIGH_GRADE >= grade; //need to calculate for highest grade but no clue
counter ++;
}
while (HIGH_GRADE >= grade); //told to use while statement to find highest grade
std::cout << grade << " is the highest grade." << std::endl;
return (0);
}
I would use an if statement to check whether the most recently entered grade is higher than HIGH_GRADE; if it is, set HIGH_GRADE to the new grade. When your instructor says "use a while loop to find the highest grade" I think s/he means like the while(counter < NMBR_OF_STUDENTS) type of while loop, and checking as you go, not using a while loop with the variables in it.
Also, please put [code][/code] tags around your code, it improves readability.
Thank you very much!!! As simple as that was I couldn't wrap my brain around it. Got it up and running and I appreciate you taking the time to help me out.