-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15.cpp
36 lines (29 loc) · 821 Bytes
/
15.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
//C++ Program to add two distances in inch feet using structure.
#include<iostream>
using namespace std;
//Structure Storing Distance in inch and feet
struct Distance
{
int feet;
float inch;
};
int main()
{
Distance d1,d2,d3;
cout<< "Enter First Distance as [feet inch]\n";
cin>> d1.feet >> d1.inch;
cout<< "Enter Second Distance as [feet inch]\n";
cin>> d2.feet >> d2.inch;
//Adding d1 and d2 and storing the sum in d3.
d3.feet = d1.feet + d2.feet;
d3.inch = d1.inch + d2.inch;
//NOTE : 12 inch = 1 feet
//If feet > 12 then feet = feet%12 and inch++
if(d3.inch > 12)
{
d3.feet++;
d3.inch = d3.inch - 12;
}
cout<< "Total Distance: " << d3.feet << " feet, " << d3.inch << " inches";
return 0;
}