fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7. int choice; //INPUT - THE CHOICES TO BE MADE 1-4
  8. float radiusCircle; //INPUT - THE RADIUS OF THE CIRCLE
  9. float lengthRectangle; //INPUT - THE LENGTH OF THE RECTANGLE
  10. float widthRectangle; //INPUT - THE WIDTH OF THE RECTANGLE
  11. float baseTriangle; //INPUT - THE BASE OF THE TRIANGLE
  12. float heightTriangle; //INPUT - THE HEIGHT OF THE TRIANGLE
  13. float areaOfCircle; //OUTPUT - THE AREA OF THE CIRCLE TO BE COMPUTED
  14. float areaOfRectangle; //OUTPUT - THE AREA OF THE RECTANGEL TO BE COMPUTED
  15. float areaOfTriangle; //OUTPUT - THE AREA OF THE TRIANGLE TO BE COMPUTED
  16.  
  17. //
  18. // Initialize the variables
  19. cout << "Geometry Calculator" << endl;
  20. cout << "1. Calculate the Area of a Circle" << endl;
  21. cout << "2. Calcualte the Area of a Rectangle" << endl;
  22. cout << "3. Calcualte the area of a Triangle" << endl;
  23. cout << "4. Quit" << endl;
  24. cin >> choice;
  25.  
  26. cout << fixed << setprecision(2) << endl;
  27. if (choice >= 0 and choice <=4) {
  28. switch (choice) {
  29. case 1:
  30. cout << "Please enter the radius of the circle " << endl;
  31. cin >> radiusCircle;
  32. if (radiusCircle > 0) {
  33. areaOfCircle = 3.14159 * (pow(radiusCircle, 2));
  34. cout << "The area of the circle is " << areaOfCircle;
  35. }
  36. else {
  37. cout << "Cannot have negative radius " << endl;
  38. }
  39. break;
  40. case 2:
  41. cout << "Please enter the length of the rectangle " << endl;
  42. cin >> lengthRectangle;
  43. if (lengthRectangle < 0 ) {
  44. cout << "Cannot have a negative length " << endl;
  45. break;
  46. }
  47.  
  48. cout << "Please enter the width of the rectangle " << endl;
  49. cin >> widthRectangle;
  50. if (widthRectangle < 0 ) {
  51. cout << "Cannot have a negative width " << endl;
  52. break;
  53. }
  54. else {
  55. areaOfRectangle = lengthRectangle * widthRectangle;
  56. cout << "The area of the of the rectangle is " << areaOfRectangle;
  57. }
  58. break;
  59. case 3:
  60. cout << "Please enter the base of the triangle " << endl;
  61. cin >> baseTriangle;
  62. if (baseTriangle < 0) {
  63. cout << "Cannot have a negative base " << endl;
  64. break;
  65. }
  66. cout << "Please enter the height of the triangle " << endl;
  67. cin >> heightTriangle;
  68. if (heightTriangle < 0) {
  69. cout << "Cannot have a negative height" << endl;
  70. break;
  71. }
  72. else {
  73. areaOfTriangle = baseTriangle * heightTriangle * .5;
  74. cout << "The area of the triangle is " << areaOfTriangle << endl;
  75. }
  76. break;
  77. case 4:
  78. cout << "Goodbye" << endl;
  79. break;
  80.  
  81.  
  82.  
  83. }
  84. }
  85. else {
  86. cout << "INVALID MENU OPTION " << endl;
  87. }
  88.  
  89.  
  90. return 0;
  91. }
  92.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Geometry Calculator
1. Calculate the Area of a Circle
2. Calcualte the Area of a Rectangle
3. Calcualte the area of a Triangle
4. Quit

INVALID MENU OPTION