-
Notifications
You must be signed in to change notification settings - Fork 23
/
4.cpp
55 lines (47 loc) · 1.13 KB
/
4.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
/*
Write a function that takes two Distance values as arguments and returns the larger one.
Include a main() program that accepts two Distance values from the user, compares
them, and displays the larger. (See the RETSTRC program for hints.)
*/
//author @Nishant
#include <iostream>
using namespace std;
struct Distance{
int feet;
float inches;
};
Distance bigD(Distance, Distance);
void display(Distance);
int main(){
Distance d1, d2, d3;
cout << "\nEnter feet: ";
cin >> d1.feet;
cout << "Enter inches: ";
cin >> d1.inches;
cout << "\nEnter feet: ";
cin >> d2.feet;
cout << "Enter inches: ";
cin >> d2.inches;
d3 = bigD(d1, d2);
cout << endl << "d1 = ";
display(d1);
cout << endl << "d2 = ";
display(d2);
cout << endl << "Largest is ";
display(d3);
cout << endl;
return 0;
}
Distance bigD(Distance d1, Distance d2){
if(d1.feet > d2.feet)
return d1;
if(d1.feet < d2.feet)
return d2;
if(d1.inches > d2.inches)
return d1;
else
return d2;
}
void display( Distance d ){
cout << d.feet << "\'-" << d.inches << "\"";
}