forked from IntroCSCI/Trio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (45 loc) · 1.02 KB
/
main.cpp
File metadata and controls
56 lines (45 loc) · 1.02 KB
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
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void sortDescending(int&,int&,int&);
void swap(int&,int&);
// <-- ADD YOUR FUNCTION PROTOTYPE HERE
int main()
{
//Takes user input and stores in int variables
int numA, numB, numC;
cout<<"Enter any three numbers: ";
cin>>numA>>numB>>numC;
//Number sorting Function
sortDescending(numA, numB, numC);
//Outputs sorted numbers to the user
cout<<"From greatest to least, they are: ";
cout<<numA<<","<<numB<<","<<numC<<endl;
return 0;
}
//Compares numbers in the list and swaps them if they pervious number is
//greater than the following
void sortDescending(int& first, int& second, int& third)
{
if( first < third )
{
swap(first,third);
}
if( first < second )
{
swap(first,second);
}
if( second < third )
{
swap(second,third);
}
}
//Helper Function to sortDescending that swaps numbers
void swap(int &first, int &second)
{
int temp = first;
first = second;
second = temp;
}
//...END OF "DO NOT CHANGE" AREA