Advertisement
skb50bd

Distance(Structure)

May 20th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct distance
  6. {
  7.     int feet;
  8.     double inches;
  9. };
  10.  
  11. struct distance calc (struct distance a, struct distance b)
  12. {
  13.     struct distance r;
  14.  
  15.     r.inches = a.inches + b.inches;
  16.  
  17.     r.feet = a.feet + b.feet;
  18.  
  19.     if(r.inches > 11)
  20.     {
  21.         r.inches -= 12;
  22.         r.feet++;
  23.     }
  24.  
  25.     return r;
  26. }
  27.  
  28. int main ()
  29. {
  30.     struct distance d1, d2, d3;
  31.  
  32.     cin >> d1.feet >> d1.inches >> d2.feet >> d2.inches;
  33.  
  34.     d3 = calc (d1, d2);
  35.  
  36.     cout << d3.feet << " " << d3.inches;
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement