change while to do #include <iostream>using namespace std;int main(){int n1,high=-1,low=101,tot=0;double avg=0; while (true)// condition always true{// body of loopcout <<"enter a grade,-1 to stop"<<endl;cin >> n1;if (n1==-1)break;++tot;avg+=n1;if (high < n1)high=n1;if (low >n1)low=n1; } //end loop cout<<"Total number of grades is "<<tot<<endl; // prints total number of grades that were inputcout<<"The highest grade is "<<high<<endl; // prints the highest gradecout<<"The lowest grade is "<<low<<endl; // prints the lowest gradeif (tot > 0)cout<<"The average grade is "<<avg/tot<<endl; //calculates the average grade return 0;}

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 7PP
icon
Related questions
Question

change while to do


#include <iostream>
using namespace std;
int main()
{
int n1,high=-1,low=101,tot=0;
double avg=0;

while (true)// condition always true
{
// body of loop
cout <<"enter a grade,-1 to stop"<<endl;
cin >> n1;
if (n1==-1)
break;
++tot;
avg+=n1;
if (high < n1)
high=n1;
if (low >n1)
low=n1;

} //end loop

cout<<"Total number of grades is "<<tot<<endl; // prints total number of grades that were input
cout<<"The highest grade is "<<high<<endl; // prints the highest grade
cout<<"The lowest grade is "<<low<<endl; // prints the lowest grade
if (tot > 0)
cout<<"The average grade is "<<avg/tot<<endl; //calculates the average grade

return 0;
}

Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage