-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrill3Végleges.cpp
76 lines (62 loc) · 2.08 KB
/
Drill3Végleges.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "std_lib_facilities.h"
int main()
{
cout << "Write | to exit \n";
//cm, m, in, ft. Assume conversion factors
//1m == 100cm,
//1in == 2.54cm,
//1ft == 12in.
double smallestSoFar = numeric_limits<double>::max();
double largestSoFar = numeric_limits<double>::min();
vector<double> v;
const double mTocm = 100, inTocm = 2.54, ftToin = 12, inTom = 0.0254, ftTom = 0.3048;
string units;
double number, sum = 0, count = 0;
cout << "Enter a number with its units (cm, m, in, ft): ";
while (cin >> number >> units) {
if (units == "in") {
cout << number << " inches is " << number * inTom << " m" << endl;
v.push_back(number * inTom);
sum += number * inTom;
if (number * inTom > largestSoFar) largestSoFar = number * inTom;
if (number * inTom < smallestSoFar) smallestSoFar = number * inTom;
count++;
}
else if (units == "m") {
cout << number << " m is " << number << " m" << endl;
v.push_back(number);
sum += number;
if (number > largestSoFar) largestSoFar = number;
if (number < smallestSoFar) smallestSoFar = number;
count++;
}
else if (units == "cm") {
cout << number << " cm is " << number / mTocm << " m" << endl;
v.push_back(number / mTocm);
sum += number / mTocm;
if (number / mTocm > largestSoFar) largestSoFar = number / mTocm;
if (number / mTocm < smallestSoFar) smallestSoFar = number / mTocm;
count++;
}
else if (units == "ft") {
cout << number << " ft is " << number * ftTom << " m" << endl;
v.push_back(number * ftTom);
sum += number * ftTom;
if (number * ftTom > largestSoFar) largestSoFar = number * ftTom;
if (number * ftTom < smallestSoFar) smallestSoFar = number * ftTom;
count++;
}
else cout << "I don't know those units!" << endl;
if (number == '|')
break;
}
cout << "The smallest so far is " << smallestSoFar << endl
<< "The largest so far is " << largestSoFar << endl
<< "The total so far is " << sum << endl
<< "Count is " << count << endl;
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
return 0;
}