Advertisement
Guest User

CSCI 140 Lab 4 -- Finn Payton

a guest
Oct 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: Finn Payton //
  3. // Course: CSCI 140 //
  4. // Assignment: Lab 4 //
  5. // Description: *** //
  6. ///////////////////////////////////////////////////////////////////////////////
  7.  
  8. #include <iostream>
  9. #include <iomanip>
  10. #include <cctype>
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15. // 1 inch = 2.54 centimeters
  16. // 1 foot = 12 inches
  17. // 1 yard = 3 feet
  18. // 1 meter = 100 centimeters
  19.  
  20. // Variable Declaration
  21. double userHeight = 0;
  22. double doorHeight = 0;
  23. double doorConv = 0; // converts to cm. to preserve user input
  24. char userHeightUnit;
  25. char doorHeightUnit;
  26. string unitLabel;
  27. bool userHeightCheck = false;
  28. bool doorHeightCheck = false;
  29.  
  30. // Constant Declaration
  31. const double I_CONV = 2.54; // cm.
  32. const double F_CONV = 30.48; // cm.
  33. const double Y_CONV = 91.44; // cm.
  34. const double M_CONV = 100.00; // cm.
  35.  
  36. // Number formatting
  37. cout << fixed << setprecision(2);
  38.  
  39. // Prompting user input
  40. cout << endl << " Welcome!" << endl << endl;
  41. cout << " Enter your height, followed by a space, followed by a" << endl;
  42. cout << " single character for unit of measurement." << endl << endl;
  43. cout << " (ex. '66 i' for '66 inches')" << endl << endl;
  44. cout << " Measurements:" << endl;
  45. cout << " " << setw(62) << setfill ('-') << "" << setfill(' ') << endl;
  46. cout << " i = inches, f = feet, y = yards, c = centimeters, m = meters";
  47. cout << endl << " " << setw(62) << setfill ('-') << "" << setfill(' ');
  48. cout << endl << endl;
  49.  
  50. // User height error checking loop & cm. conversions
  51. do {
  52.  
  53. cout << " ";
  54. cin >> userHeight;
  55. cin >> userHeightUnit;
  56.  
  57. while (userHeight <= 0){ // Disallows negative input
  58. cout << endl;
  59. cout << " Your height must be greater than zero!" << endl << endl;
  60. cout << " Please re-input your height, followed by a" << endl;
  61. cout << " single character for unit of measurement." << endl;
  62. cout << endl << " ";
  63. cin >> userHeight;
  64. cin >> userHeightUnit;
  65. }
  66.  
  67. userHeightUnit = toupper(userHeightUnit); // makes uppercase
  68.  
  69. switch (userHeightUnit) {
  70. case 'I':
  71. cout << endl << " Great, you are " << userHeight;
  72. cout << " inches tall!";
  73. userHeight = userHeight * I_CONV;
  74. userHeightCheck = true;
  75. break;
  76. case 'F':
  77. cout << endl << " Great, you are " << userHeight;
  78. cout << " feet tall!";
  79. userHeight = userHeight * F_CONV;
  80. userHeightCheck = true;
  81. break;
  82. case 'Y':
  83. cout << endl << " Great, you are " << userHeight;
  84. cout << " yards tall!";
  85. userHeight = userHeight * Y_CONV;
  86. userHeightCheck = true;
  87. break;
  88. case 'M':
  89. cout << endl << " Great, you are " << userHeight;
  90. cout << " meters tall!";
  91. userHeight = userHeight * M_CONV;
  92. userHeightCheck = true;
  93. break;
  94. case 'C': // centimeter conversion unnecessary
  95. cout << endl << " Great, you are " << userHeight;
  96. cout << " centimeters tall!";
  97. userHeightCheck = true;
  98. break;
  99. default:
  100. cout << endl;
  101. cout << " Please only enter a unit from the list above.";
  102. }
  103.  
  104. cout << endl << endl;
  105.  
  106. } while (userHeightCheck != true);
  107.  
  108. // Prompting user input
  109. cout << " Enter the height of the doorway, followed by a space," << endl;
  110. cout << " followed by a single character for unit of measurement." << endl;
  111. cout << " (ex. '4 y' for '4 yards')" << endl << endl;
  112. cout << " Measurements:" << endl;
  113. cout << " " << setw(62) << setfill ('-') << "" << setfill(' ') << endl;
  114. cout << " i = inches, f = feet, y = yards, c = centimeters, m = meters";
  115. cout << endl << " " << setw(62) << setfill ('-') << "" << setfill(' ');
  116. cout << endl << endl;
  117.  
  118. // Doorway height error checking loop & cm. conversions
  119. do {
  120.  
  121. cout << " ";
  122. cin >> doorHeight;
  123. cin >> doorHeightUnit;
  124.  
  125. doorHeightUnit = toupper(doorHeightUnit); // makes uppercase
  126.  
  127. switch (doorHeightUnit) {
  128. case 'I':
  129. cout << endl << " Great, the doorway is " << doorHeight;
  130. cout << " inches tall!";
  131. doorConv = doorHeight * I_CONV;
  132. unitLabel = "inches";
  133. doorHeightCheck = true;
  134. break;
  135. case 'F':
  136. cout << endl << " Great, the doorway is " << doorHeight;
  137. cout << " feet tall!";
  138. doorConv = doorHeight * F_CONV;
  139. unitLabel = "feet";
  140. doorHeightCheck = true;
  141. break;
  142. case 'Y':
  143. cout << endl << " Great, the doorway is " << doorHeight;
  144. cout << " yards tall!";
  145. doorConv = doorHeight * Y_CONV;
  146. unitLabel = "yards";
  147. doorHeightCheck = true;
  148. break;
  149. case 'M':
  150. cout << endl << " Great, the doorway is " << doorHeight;
  151. cout << " meters tall!";
  152. doorConv = doorHeight * M_CONV;
  153. unitLabel = "meters";
  154. doorHeightCheck = true;
  155. break;
  156. case 'C': // centimeter conversion unnecessary
  157. cout << endl << " Great, the doorway is " << doorHeight;
  158. cout << " centimeters tall!";
  159. unitLabel = "centimeters";
  160. doorHeightCheck = true;
  161. break;
  162. default:
  163. cout << endl;
  164. cout << " Please only enter a unit from the list above.";
  165. }
  166.  
  167. cout << endl << endl;
  168.  
  169. } while (doorHeightCheck != true);
  170.  
  171. // Calculations for door user height vs. door height
  172. if (doorConv > userHeight * 1.25){
  173. cout << " For a door at " << doorHeight << " " << unitLabel << endl;
  174. cout << " you should use STILTS." << endl;
  175. }
  176. else if (doorConv <= userHeight * 1.25 && doorConv > userHeight * 1.05){
  177. cout << " For a door at " << doorHeight << " " << unitLabel << endl;
  178. cout << " you should WALK." << endl;
  179. }
  180. else if (doorConv <= userHeight * 1.05 && doorConv > userHeight * 0.65){
  181. cout << " For a door at " << doorHeight << " " << unitLabel << endl;
  182. cout << " you should DUCK." << endl;
  183. }
  184. else if (doorConv <= userHeight * 0.65 && doorConv > userHeight * 0.40){
  185. cout << " For a door at " << doorHeight << " " << unitLabel << endl;
  186. cout << " you should CRAWL." << endl;
  187. }
  188. else if (doorConv <= userHeight * 0.40 && doorConv > userHeight * 0.25){
  189. cout << " For a door at " << doorHeight << " " << unitLabel << endl;
  190. cout << " you should LIMBO." << endl;
  191. }
  192. else if (doorConv <= userHeight * 0.25){
  193. cout << " For a door at " << doorHeight << " " << unitLabel << endl;
  194. cout << " your path is BLOCKED." << endl;
  195. }
  196.  
  197. return 0;
  198.  
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement