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;

}

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;

}

``

## Comments

## Leave a comment