Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.4k views
in Arrays and Structures by (49.1k points)
closed by

Write a C++ program to add two distances using the following structure definition, struct Distance!

int feet;

float inch;

}d1, d2, sum;

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

int main()

{

cout<<“Enter 1st distance:”<<end1;

cout<<“Enter feet:”; cin>>d1.feet;

cout <<“Enter inch:”; cin >> d1.inch;

cout << “\n information for 2nd distance:” << end1;

cout<<“Enter feet:”; cin >> d2.feet;

cout <<“Enter inch:”; 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 << end1; “Sum of distance = ” <<

sum.feet << “feet” << sum.inch <<“inches”;

return 0;

}

Output:

Enter 1 st distance

Enter feet: 6

Enter inch: 3.4

Enter 2nd distance

Enter feet: 5

Enter inch: 10.2

Sum of distances = 12 feet 1.6 inches

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...