Advertisement
makispaiktis

Converts

Aug 25th, 2018 (edited)
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     cout << "This is a programme about converts in length units." << endl;
  8.     cout << "The units that are used in this programme are: " << endl << endl;
  9.     cout << "Meters (and dm and cm), yards, feet and inches" << endl;
  10.     cout << "There are the following choices: " << endl << endl;
  11.     cout << "1.  Meter ---> Yard" << endl;
  12.     cout << "2.  Meter ---> Feet" << endl;
  13.     cout << "3.  Meter ---> Inch" << endl;
  14.     cout << "4.  Yard ---> Meter" << endl;
  15.     cout << "5.  Yard ---> Feet" << endl;
  16.     cout << "6.  Yard ---> Inch" << endl;
  17.     cout << "7.  Feet ---> Yard" << endl;
  18.     cout << "8.  Feet ---> Feet" << endl;
  19.     cout << "9.  Feet ---> Inch" << endl;
  20.     cout << "10. Inch ---> Meter" << endl;
  21.     cout << "11. Inch ---> Feet" << endl;
  22.     cout << "12. Inch ---> Inch" << endl << endl;
  23.  
  24.     // Ask from the user which convert to do
  25.     cout << "Press a number from 1 to 12 to choose which convert do you want me to do." << endl;
  26.     int choice;
  27.     cin >> choice;
  28.  
  29.     double data;
  30.  
  31.     // The convert is:
  32.     // 1 foot = 0.305 meters
  33.     // 1 foot = 12 inches , so inch = 2.54 cm
  34.     // 1 yard = 3 feet = 36 inches, so yard = 0.915 meters
  35.     switch(choice){
  36.  
  37.     case 1:
  38.  
  39.         cout << "How many meters? " << endl << endl;
  40.         cin >> data;
  41.         cout << data << " meters = " << data * 10 << " dm = " << data * 100 << " cm = ";
  42.         cout << 1000 * data << " mm = " << 1 / 0.915 * data << " yards " << endl << endl;
  43.  
  44.     case 2:
  45.  
  46.         cout << "How many meters? " << endl << endl;
  47.         cin >> data;
  48.         cout << data << " meters = " << data * 10 << " dm = " << data * 100 << " cm = ";
  49.         cout << 1000 * data << " mm = " << 1 / 0.305 * data << " yards " << endl << endl;
  50.  
  51.     case 3:
  52.  
  53.         cout << "How many meters? " << endl << endl;
  54.         cin >> data;
  55.         cout << data << " meters = " << data * 10 << " dm = " << data * 100 << " cm = ";
  56.         cout << 1000 * data << " mm = " << 1 / (0.305 / 12) * data << " yards " << endl << endl;
  57.  
  58.     case 4:
  59.  
  60.         cout << "How many yards? " << endl << endl;
  61.         cin >> data;
  62.         cout << data << " yards = " << 0.915 * data << " meters = " << 9.15 * data << " dm = ";
  63.         cout << 91.5 * data << " cm = " << 915 * data << " mm" << endl << endl;
  64.  
  65.     case 5:
  66.  
  67.         cout << "How many yards? " << endl << endl;
  68.         cin >> data;
  69.         cout << data << " yards = " << 3 * data << " feet" << endl << endl;
  70.  
  71.  
  72.     case 6:
  73.  
  74.         cout << "How many yards? " << endl << endl;
  75.         cin >> data;
  76.         cout << data << " yards = " << 36 * data << " inches" << endl << endl;
  77.  
  78.    default:;
  79.  
  80.     }
  81.  
  82.     return 0;
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement