Guest User

Untitled

a guest
Jun 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.  
  9.  
  10.  
  11. //Declaration of Variables.
  12. double circleArea, rectangleArea, triangleArea,
  13. length, width, height, base, radius;
  14. char choice;
  15. const double PI = 3.14159;
  16.  
  17.  
  18. //Display the menu.
  19.  
  20. cout << "\tGeometry Calculator" << endl << endl;
  21. cout << setw(10) << "1. Calculate the Area of a Circle" << endl;
  22. cout << setw(10) << "2. Calculate the Area of a Rectangle" << endl;
  23. cout << setw(10) << "3. Calculate the Area of a Triangle" << endl;
  24. cout << setw(6) << "4. Quit" << endl;
  25.  
  26. cout << endl;
  27.  
  28. //Prompt User for choice.
  29.  
  30. cout << "Enter your choice (1-4)" << endl;
  31. cin >> choice;
  32. cout << endl;
  33.  
  34.  
  35. //Calculate the area of a Circle.
  36.  
  37. switch (choice)
  38. {
  39.  
  40. case 'C':
  41. case 'c':
  42. case '1':
  43.  
  44. cout << "Enter the radius of the circle: ";
  45. cin >> radius;
  46.  
  47. if (radius < 0)
  48. {
  49. cout << "Number must be greater than 0. Try again" << endl;
  50. }
  51. else
  52. {
  53. circleArea = PI * pow(radius, 2);
  54. cout << "The area of the circle is: " << circleArea;
  55. }
  56.  
  57. cout << endl;
  58.  
  59. break;
  60.  
  61.  
  62. //Calculate the area of a Rectangle.
  63.  
  64. case 'R':
  65. case 'r':
  66. case '2':
  67.  
  68. cout << "Enter the length and width of the rectangle: ";
  69. cin >> length >> width;
  70.  
  71. if (length < 0 || width < 0)
  72. {
  73. cout << "Number must be greater than 0. Try again" << endl;
  74. }
  75. else
  76. {
  77. rectangleArea = length * width;
  78. cout << "The area of the rectangle is: " << rectangleArea;
  79. }
  80.  
  81. cout << endl;
  82.  
  83. break;
  84.  
  85.  
  86. //Calculate the area of a Triangle.
  87.  
  88. case 'T':
  89. case 't':
  90. case '3':
  91.  
  92. cout << "Enter the base and height of the triangle: ";
  93. cin >> base >> height;
  94.  
  95. if (base < 0 || height < 0)
  96. {
  97. cout << "Number must be greater than 0. Try again" << endl;
  98. }
  99. else
  100. {
  101. triangleArea = base * height * .5;
  102. cout << "The area of the triangle is: " << triangleArea;
  103. }
  104.  
  105. cout << endl;
  106.  
  107. break;
  108.  
  109.  
  110. //Quit the program.
  111.  
  112. case 'Q':
  113. case 'q':
  114. case '4':
  115.  
  116. cout << "End of Program" << endl;
  117. cout << endl;
  118.  
  119. break;
  120.  
  121.  
  122. //Invalid number.
  123.  
  124. default:
  125.  
  126. cout << "That is an invalid choice." << endl;
  127. cout << "Please select choices 1-4." << endl;
  128.  
  129. break;
  130. }
  131.  
  132. return 0;
  133. }
Add Comment
Please, Sign In to add comment