fork download
  1. // Castulo Jason Quintero CSC5 Chapter 4, pg. 225, #21
  2. //
  3. /*******************************************************************************
  4.  * Calculate Area of Selected Shape
  5.  * _____________________________________________________________________________
  6.  * This program will accept user input for a selected shape and computes the
  7.  * area of the shape
  8.  * _____________________________________________________________________________
  9.  * INPUT
  10.  * menuOption : User's menu selection
  11.  * numOne : First user input value for shape
  12.  * numTwo : Second user input value for shape
  13.  *
  14.  * OUTPUT
  15.  * result : Calculated area of shape
  16.  ******************************************************************************/
  17.  
  18. #include <iostream>
  19. #include <cmath>
  20. using namespace std;
  21.  
  22. int main() {
  23. const float pi = 3.14159; // constant PI
  24. int menuOption; // INPUT - user's menu selection
  25. float numOne; // INPUT - user input value
  26. float numTwo; // INPUT - second user input value
  27. float result; // OUTPUT - result of the calculation
  28.  
  29. //displaying menu options to user
  30. cout << "Geometry Calcuator\n\n"
  31. "1. Calculate the Area of a Circle\n"
  32. "2. Calculate the Area of a Rectangle\n"
  33. "3. Calculate the Area of a Triangle\n"
  34. "4. Quit" << endl;
  35. cin >> menuOption;
  36.  
  37. // menu cases depending on option selected by user
  38. switch (menuOption) {
  39. case 1:
  40. cout << "what is the circles radius?: ";
  41. cin >> numOne;
  42. result = pi * (powf(numOne, 2));
  43. cout << "area of the circle is " << result;
  44. break;
  45. case 2:
  46. cout << "\nwhat is the length of the rectangle?: ";
  47. cin >> numOne;
  48. cout << "\nwhat is the width of the rectangle?: ";
  49. cin >> numTwo;
  50. result = numOne * numTwo;
  51. cout << "\nthe area of the rectangle is " << result << endl;
  52. break;
  53. case 3:
  54. cout << "\nwhat is the triangles base?: ";
  55. cin >> numOne;
  56. cout << "\nwhat is the triangles height?: ";
  57. cin >> numTwo;
  58. result = (numOne * numTwo) * .5f;
  59. cout << "\nthe area of the triangle is " << result << endl;
  60. break;
  61. case 4:
  62. cout << "\nEnd program.";
  63. break;
  64. default:
  65. cout << "\nERROR: invalid entry" << endl;
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0s 5300KB
stdin
3
8
10
stdout
Geometry Calcuator

1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit

what is the triangles base?: 
what is the triangles height?: 
the area of the triangle is 40