-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargestFunc.cpp
More file actions
68 lines (51 loc) · 1.21 KB
/
largestFunc.cpp
File metadata and controls
68 lines (51 loc) · 1.21 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
57
58
59
60
61
62
63
64
65
66
67
68
/****************************
James Bertel
CS111
Lab 5-1
10-11-17
This program will read 3 numbers from the user and tell the largest number.
*****************************/
#include<iostream>
using namespace std;
void showProgInfo();
int getNum();
int findLargest(int n1, int n2, int n3);
void printResult(int n1, int n2, int n3, int largest);
int main()
{
showProgInfo();
int num1 = getNum();
int num2 = getNum();
int num3 = getNum();
int large = findLargest(num1, num2, num3);
printResult(num1, num2, num3, large);
return 0;
}
void showProgInfo()
{
cout << "*****************************************************" << endl;
cout << "This program will ask you to enter 3 numbers and find the largest." << endl;
cout << "*****************************************************" << endl;
}
int getNum()
{
int num;
cout << "Enter a number : ";
cin >> num;
return num;
}
int findLargest(int n1, int n2, int n3)
{
int largest;
if(n1>n2)
largest = n1;
else //n2>=n1
largest = n2;
if(n3>largest)
largest = n3;
return largest;
}
void printResult(int n1, int n2, int n3, int largest)
{
cout << "The largest number among " << n1 << ", " << n2 << " and " << n3 << " is " << largest << ".\n";
}