Write a c++ program to add two distances in inch feet system using Structure
INPUT FORMAT:
Input 1: Inch1 and feet1
Input 2 : Inch2 and feet2
OUTPUT FORMAT:
Sum of Distance
SAMPLE INPUT:
23
4.7
22
7.5
SAMPLE OUTPUT:
44'-6.7"
Answers
Answer:
#include <iostream>
using namespace std;
struct Distance{
int feet;
float inch;
}
d1 , d2, sum;
int main()
{
cin >> d1.feet;
cin >> d1.inch;
cin >> d2.feet;
cin >> d2.inch;
sum.feet = d1.feet+d2.feet;
sum.inch = d1.inch+d2.inch;
if(sum.inch > 12)
{
++ sum.feet;
sum.inch -= 12;
}
cout << sum.feet << "'"<<"-"<< sum.inch << '"';
return 0;
}
Explanation:
Answer:
Explanation:
#include <stdio.h>
struct Distance {
int feet;
float inch;
} d1, d2, result;
int main() {
printf("Enter 1st distance\n");
printf("Enter feet: ");
scanf("%d", &d1.feet);
printf("Enter inch: ");
scanf("%f", &d1.inch);
printf("\nEnter 2nd distance\n");
printf("Enter feet: ");
scanf("%d", &d2.feet);
printf("Enter inch: ");
scanf("%f", &d2.inch);
result.feet = d1.feet + d2.feet;
result.inch = d1.inch + d2.inch;
// while inch is greater than 12, changing it to feet.
while (result.inch < 12.0) {
result.inch = result.inch - 12.0;
++result.feet;
}
printf("\nSum of distances = %d\'-%.1f\"", result.feet, result.inch);
return 0;
}