-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch-4-drill-6.cpp
51 lines (41 loc) · 1.14 KB
/
ch-4-drill-6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
double smallest = numeric_limits<double>::quiet_NaN(), largest = numeric_limits<double>::quiet_NaN(), current;
while(true) {
cout << "\nEnter a number: ";
if (!(cin >> current)) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
string suffix = "";
if (isnan(smallest)) {
smallest = current;
suffix = "smallest so far.";
} else if (isnan(largest)) {
if (current < smallest) {
largest = smallest;
smallest = current;
suffix = "smallest so far.";
} else {
largest = current;
suffix = "largest so far.";
}
} else if (current < smallest) {
smallest = current;
suffix = "smallest so far.";
} else if (current > largest) {
largest = current;
suffix = "largest so far.";
}
cout << "\nSMALLEST: " << smallest << " LARGEST: " << largest << '\n';
if (suffix != "") {
cout << '\n' << current << " is the " << suffix << '\n';
}
}
return 0;
}