-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberSort.h
64 lines (56 loc) · 1.07 KB
/
NumberSort.h
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
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int c;
char Cont = 'y';
while (Cont == 'y' || Cont == 'Y')
{
cout << "Please enter three numbers to be sorted: ";
cin >> a >> b >> c;
if (a > b && a > c) //Compare if a is greater than b and c to leave as largest integer.
{
if (b > c)
{
cout << c << " " << b << " " << a << endl;
}
else
{
cout << b << " " << c << " " << a << endl;
}
}
else if (b > c && b > a) // If a is not largest, compare b to a and c.
{
if (a > c)
{
cout << c << " " << a << " " << b << endl;
}
else
{
cout << a << " " << c << " " << b << endl;
}
}
else if (c > a && c > b) // if b and a are not largest compare c.
{
if (a > b)
{
cout << b << " " << a << " " << c << endl;
}
else
{
cout << a << " " << b << " " << c << endl;
}
}
else // If non-numbers are input, end program.
{
cout << "These are not valid integers.";
cin.clear();
return 0;
}
cout << "Try another set? (Y/N): ";
cin >> Cont;
}
return 0;
}