20.3k views
5 votes
Write a C++ program using a do while loop for (Find the highest score). The program should work for any number of students. Run the program for 3 cases:

1 Answer

2 votes

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int highest = 0;
  6. int score;
  7. do{
  8. cout<<"Input a score: ";
  9. cin>>score;
  10. if(score > highest){
  11. highest = score;
  12. }
  13. }while(score >= 0);
  14. cout<<highest;
  15. return 0;
  16. }

Step-by-step explanation:

Firstly, create a variable highest and initialize it with zero (Line 5). Next, create a do while loop (Line 7 - 14). Within the loop prompt user to input a score (Line 8-9) and if the current score is higher than the highest variable, assign the score to highest variable (Line 11 - 13).

After finishing the loop when user put in any negative value, the program shall be able to print out the highest input score (Line 16).

User Glazed
by
7.8k points

No related questions found