63 149
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #48217 in C++ for Eunsu Kim

Question #48217
Reads just one double each time around by while loop. define two variables to keep track of which is the smallest and which is the largest value you have seen so far. Each time through the loop write out the value entered. If it's the smallest so far, write the "the smallest so far" after the number. If it is the largest so far, write "the largest so far" after the number.
Expert's answer
#include <iostream>
 
using namespace std;
 
int main() {
               intmax(0),
                              min(0),
                              current;
               boolfirst = true;
 
               while(1) {
                              cout<< "Input number: ";
                              cin>> current;
                              if(first) {
                                            max= current;
                                            min= current;
                                            first= false;
                              }
                              cout<< "Your number is " << current;
                              if(current >= max) {
                                            max= current;
                                            cout<< " the largest so far";
                              }
                              if(current <= min) {
                                            min= current;
                                            cout<< " the smallest so far";
                              }
                              cout<< endl;
               }
               return0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions