Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std_lib_facilities.h" // from http://www.stroustrup.com/Programming/std_lib_facilities.h
- //includes facilities.h --> http://www.stroustrup.com/Programming/std_lib_facilities.h
- int main()
- {
- char CorrectAcoordingToUser = 'n'; //declare vars
- char MorK = 'x';
- int distance = -1;
- float distanceOutput;
- //make sure it loops if user input is incorrect
- while ((CorrectAcoordingToUser != 'y') || ((MorK != 'M') && (MorK != 'K')) || (distance == -1))
- {
- cout << "Enter what you'd like to convert (M of K),\nthen enter a space followed by the distance\n";
- CorrectAcoordingToUser = 'n'; // makes sure if user enters some bullshit value, the program resets it
- // input below
- cin >> MorK >> distance; //input M or K, followed by distance
- cout << "you entered " << distance << ' ' << MorK << ". Is this correct?\n\n";
- cout << "Enter y or n \n"; //check if input is correct according to user
- cin >> CorrectAcoordingToUser;
- cout << "You entered " << CorrectAcoordingToUser << "\n";
- if (CorrectAcoordingToUser == 'n')
- {
- cout << "\nYou decided input is incorrect. Please try again \n";
- }
- }
- if (CorrectAcoordingToUser == 'y')
- {
- // differentiate between M --> K and K --> M
- //distance = K
- if (MorK == 'K')
- {
- distanceOutput = distance / 1000;
- cout << "distance is: " << distanceOutput << " " << MorK << "\n";
- }
- //distance = M
- if (MorK == 'M')
- {
- distanceOutput = distance * 1000;
- cout << "distance is: " << distanceOutput << " " << MorK << "\n";
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment