Guest User

Untitled

a guest
Aug 14th, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include "std_lib_facilities.h" // from http://www.stroustrup.com/Programming/std_lib_facilities.h
  2.  
  3. //includes facilities.h --> http://www.stroustrup.com/Programming/std_lib_facilities.h
  4.  
  5.  
  6. int main()
  7. {
  8.     char CorrectAcoordingToUser = 'n'; //declare vars
  9.     char MorK = 'x';
  10.     int distance = -1;
  11.     float distanceOutput;
  12.    
  13.  
  14.     //make sure it loops if user input is incorrect
  15.     while ((CorrectAcoordingToUser != 'y') || ((MorK != 'M') && (MorK != 'K')) || (distance == -1))
  16.     {
  17.         cout << "Enter what you'd like to convert (M of K),\nthen enter a space followed by the distance\n";
  18.         CorrectAcoordingToUser = 'n'; // makes sure if user enters some bullshit value, the program resets it
  19.         // input below
  20.        
  21.         cin >> MorK >> distance; //input M or K, followed by distance
  22.  
  23.         cout << "you entered " << distance << ' ' << MorK << ". Is this correct?\n\n";
  24.         cout << "Enter y or n \n"; //check if input is correct according to user
  25.  
  26.         cin >> CorrectAcoordingToUser;
  27.  
  28.         cout << "You entered " << CorrectAcoordingToUser << "\n";
  29.  
  30.         if (CorrectAcoordingToUser == 'n')
  31.         {
  32.             cout << "\nYou decided input is incorrect. Please try again \n";
  33.    
  34.  
  35.         }
  36.  
  37.     }
  38.  
  39.  
  40.  
  41.     if (CorrectAcoordingToUser == 'y')
  42.     {
  43.         // differentiate between M --> K and K --> M
  44.        
  45.         //distance = K
  46.         if (MorK == 'K')
  47.         {
  48.             distanceOutput = distance / 1000;
  49.             cout << "distance is: " << distanceOutput << " " << MorK << "\n";
  50.  
  51.  
  52.         }
  53.         //distance = M
  54.         if (MorK == 'M')
  55.         {
  56.  
  57.             distanceOutput = distance * 1000;
  58.             cout << "distance is: " << distanceOutput << " " << MorK << "\n";
  59.  
  60.         }
  61.     }
  62.  
  63.     return 0;
  64.  
  65.  
  66. }
Add Comment
Please, Sign In to add comment