Program for the addition of two distances using structure in CPP (C plus plus)

Program for the addition of two distances using structure in CPP (C plus plus)

In this tutorial, we will learn about Program for the addition of two distances using structure in CPP (C plus plus).

#include <iostream>

using namespace std;

struct distance{
    int feets;
    float inches;
}
d1 , d2, add;

int main()
{
    cout<<"Please enter first distance: "<<endl;
    
	cout<<"Please enter feets: ";
    cin>>d1.feets;
    
    cout<<"Please enter inches: ";
    cin >> d1.inches;

    cout<<endl<<"Pleas enter second distance: "<<endl;
   
    cout<<"Please enter feets: ";
    cin>>d2.feets;
   
    cout<<"Please enter inches: ";
    cin>>d2.inches;

    add.feets=d1.feets+d2.feets;
    add.inches=d1.inches+d2.inches;

        if(add.inches > 12)
    {
        ++ add.feets;
        add.inches -= 12;
    } 

    cout<<endl<<"The sum of distances= "<<add.feets<<" feet  "<<add.inches<< " inches";
    return 0;
}

Output:

Program for the addition of two distances using structure in CPP (C plus plus)
Program for the addition of two distances using a structure in CPP (C plus plus)
Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.