Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////
- // Name: Finn Payton //
- // Course: CSCI 140 //
- // Assignment: Lab 4 //
- // Description: *** //
- ///////////////////////////////////////////////////////////////////////////////
- #include <iostream>
- #include <iomanip>
- #include <cctype>
- using namespace std;
- int main()
- {
- // 1 inch = 2.54 centimeters
- // 1 foot = 12 inches
- // 1 yard = 3 feet
- // 1 meter = 100 centimeters
- // Variable Declaration
- double userHeight = 0;
- double doorHeight = 0;
- double doorConv = 0; // converts to cm. to preserve user input
- char userHeightUnit;
- char doorHeightUnit;
- string unitLabel;
- bool userHeightCheck = false;
- bool doorHeightCheck = false;
- // Constant Declaration
- const double I_CONV = 2.54; // cm.
- const double F_CONV = 30.48; // cm.
- const double Y_CONV = 91.44; // cm.
- const double M_CONV = 100.00; // cm.
- // Number formatting
- cout << fixed << setprecision(2);
- // Prompting user input
- cout << endl << " Welcome!" << endl << endl;
- cout << " Enter your height, followed by a space, followed by a" << endl;
- cout << " single character for unit of measurement." << endl << endl;
- cout << " (ex. '66 i' for '66 inches')" << endl << endl;
- cout << " Measurements:" << endl;
- cout << " " << setw(62) << setfill ('-') << "" << setfill(' ') << endl;
- cout << " i = inches, f = feet, y = yards, c = centimeters, m = meters";
- cout << endl << " " << setw(62) << setfill ('-') << "" << setfill(' ');
- cout << endl << endl;
- // User height error checking loop & cm. conversions
- do {
- cout << " ";
- cin >> userHeight;
- cin >> userHeightUnit;
- while (userHeight <= 0){ // Disallows negative input
- cout << endl;
- cout << " Your height must be greater than zero!" << endl << endl;
- cout << " Please re-input your height, followed by a" << endl;
- cout << " single character for unit of measurement." << endl;
- cout << endl << " ";
- cin >> userHeight;
- cin >> userHeightUnit;
- }
- userHeightUnit = toupper(userHeightUnit); // makes uppercase
- switch (userHeightUnit) {
- case 'I':
- cout << endl << " Great, you are " << userHeight;
- cout << " inches tall!";
- userHeight = userHeight * I_CONV;
- userHeightCheck = true;
- break;
- case 'F':
- cout << endl << " Great, you are " << userHeight;
- cout << " feet tall!";
- userHeight = userHeight * F_CONV;
- userHeightCheck = true;
- break;
- case 'Y':
- cout << endl << " Great, you are " << userHeight;
- cout << " yards tall!";
- userHeight = userHeight * Y_CONV;
- userHeightCheck = true;
- break;
- case 'M':
- cout << endl << " Great, you are " << userHeight;
- cout << " meters tall!";
- userHeight = userHeight * M_CONV;
- userHeightCheck = true;
- break;
- case 'C': // centimeter conversion unnecessary
- cout << endl << " Great, you are " << userHeight;
- cout << " centimeters tall!";
- userHeightCheck = true;
- break;
- default:
- cout << endl;
- cout << " Please only enter a unit from the list above.";
- }
- cout << endl << endl;
- } while (userHeightCheck != true);
- // Prompting user input
- cout << " Enter the height of the doorway, followed by a space," << endl;
- cout << " followed by a single character for unit of measurement." << endl;
- cout << " (ex. '4 y' for '4 yards')" << endl << endl;
- cout << " Measurements:" << endl;
- cout << " " << setw(62) << setfill ('-') << "" << setfill(' ') << endl;
- cout << " i = inches, f = feet, y = yards, c = centimeters, m = meters";
- cout << endl << " " << setw(62) << setfill ('-') << "" << setfill(' ');
- cout << endl << endl;
- // Doorway height error checking loop & cm. conversions
- do {
- cout << " ";
- cin >> doorHeight;
- cin >> doorHeightUnit;
- doorHeightUnit = toupper(doorHeightUnit); // makes uppercase
- switch (doorHeightUnit) {
- case 'I':
- cout << endl << " Great, the doorway is " << doorHeight;
- cout << " inches tall!";
- doorConv = doorHeight * I_CONV;
- unitLabel = "inches";
- doorHeightCheck = true;
- break;
- case 'F':
- cout << endl << " Great, the doorway is " << doorHeight;
- cout << " feet tall!";
- doorConv = doorHeight * F_CONV;
- unitLabel = "feet";
- doorHeightCheck = true;
- break;
- case 'Y':
- cout << endl << " Great, the doorway is " << doorHeight;
- cout << " yards tall!";
- doorConv = doorHeight * Y_CONV;
- unitLabel = "yards";
- doorHeightCheck = true;
- break;
- case 'M':
- cout << endl << " Great, the doorway is " << doorHeight;
- cout << " meters tall!";
- doorConv = doorHeight * M_CONV;
- unitLabel = "meters";
- doorHeightCheck = true;
- break;
- case 'C': // centimeter conversion unnecessary
- cout << endl << " Great, the doorway is " << doorHeight;
- cout << " centimeters tall!";
- unitLabel = "centimeters";
- doorHeightCheck = true;
- break;
- default:
- cout << endl;
- cout << " Please only enter a unit from the list above.";
- }
- cout << endl << endl;
- } while (doorHeightCheck != true);
- // Calculations for door user height vs. door height
- if (doorConv > userHeight * 1.25){
- cout << " For a door at " << doorHeight << " " << unitLabel << endl;
- cout << " you should use STILTS." << endl;
- }
- else if (doorConv <= userHeight * 1.25 && doorConv > userHeight * 1.05){
- cout << " For a door at " << doorHeight << " " << unitLabel << endl;
- cout << " you should WALK." << endl;
- }
- else if (doorConv <= userHeight * 1.05 && doorConv > userHeight * 0.65){
- cout << " For a door at " << doorHeight << " " << unitLabel << endl;
- cout << " you should DUCK." << endl;
- }
- else if (doorConv <= userHeight * 0.65 && doorConv > userHeight * 0.40){
- cout << " For a door at " << doorHeight << " " << unitLabel << endl;
- cout << " you should CRAWL." << endl;
- }
- else if (doorConv <= userHeight * 0.40 && doorConv > userHeight * 0.25){
- cout << " For a door at " << doorHeight << " " << unitLabel << endl;
- cout << " you should LIMBO." << endl;
- }
- else if (doorConv <= userHeight * 0.25){
- cout << " For a door at " << doorHeight << " " << unitLabel << endl;
- cout << " your path is BLOCKED." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement