Defining a structurestruct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.
Syntax :struct structure_name{//Statements};
#include <iostream> using namespace std; struct Distance { int feet; float inch; }d1,d2,sum; int main() { cout << "Enter information for 1st distance" << endl; cout << "Enter feet: "; cin >> d1.feet; cout << "Enter inch: "; cin >> d1.inch; cout << endl << "Enter information for 2nd distance" << endl; cout << "Enter feet: "; cin >> d2.feet; cout << "Enter inch: "; cin >> d2.inch; sum.feet=d1.feet+d2.feet; sum.inch=d1.inch+d2.inch; do { sum.inch=sum.inch-12.0; ++sum.feet; }while(sum.inch>12.0); cout << endl << "Sum of distances= " << sum.feet << " feet " << sum.inch << " inch"; return 0; }
Output:
Enter information for 1st distance
Enter feet: 23
Enter inch: 6
Enter information for 2nd distance
Enter feet: 52
Enter inch: 8
Sum of distances= 76 feet 2 inch
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
Enter information for 1st distance
Enter feet: 23
Enter inch: 6
Enter information for 2nd distance
Enter feet: 52
Enter inch: 8
Sum of distances= 76 feet 2 inch
need an explanation for this answer? contact us directly to get an explanation for this answer