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