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.
1
Expert's answer
2014-10-28T01:42:57-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS