fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7.  
  8. {
  9. int n;
  10.  
  11. cout << "Geometry Calculator" <<endl <<endl;
  12. cout << "1. Calculate the Area of a Circle" <<endl;
  13. cout << "2. Calculate the Area of a Rectangle" <<endl;
  14. cout << "3. Calculate the Area of a Triangle" <<endl;
  15. cout << "4. Quit" <<endl;
  16.  
  17. cout << "Enter 1,2,3, or 4: ";
  18. cin >> n;
  19.  
  20. if (n==1)
  21.  
  22. {
  23. float pi= 3.14159;
  24. float r;
  25.  
  26. cout <<"Enter the radius of the circle: ";
  27. cin >> r;
  28.  
  29. if(r<0)
  30. { cout << "ERROR! Enter a positive number.\n";}
  31.  
  32. if (r>0)
  33. cout << "The area of the circle is " <<fixed <<setprecision(2) << (2*pi*r) << " square\n";
  34. }
  35.  
  36. if (n==2)
  37.  
  38. {
  39. float l,w;
  40.  
  41. cout << "Enter the length of the rectangle: ";
  42. cin >> l;
  43.  
  44. if(l<0)
  45. {cout << "ERROR!Enter a positive number.\n";}
  46.  
  47. cout << "Enter the width of the rectangle: ";
  48. cin >> w;
  49.  
  50. if(w<0)
  51. {cout << "ERROR! Enter a positive number.\n";}
  52.  
  53. if (l>=0&&w>=0)
  54. cout << "The area of the rectangle is " << l*w << " sqaure\n";
  55. else if (l<0||w<0)
  56. cout << "Error! Enter a positive number.";
  57.  
  58. }
  59.  
  60. if (n==3)
  61.  
  62. {
  63. float base,height;
  64.  
  65. cout <<"Enter the base of the triangle: ";
  66. cin>> base;
  67. if(base<0)
  68. { cout <<"ERROR! Enter a positive number.\n";}
  69.  
  70. cout <<"Enter the height of the triangle: ";
  71. cin>> height;
  72.  
  73. if(height<0)
  74. {cout << "ERROR! Enter a positive number.\n";}
  75.  
  76.  
  77. if (base>=0&&height>=0)
  78. cout << "The area of the triangle is " << base*height <<" square\n";
  79. else if (base<0||height<0)
  80. cout << "Error! Enter a positive number.";
  81.  
  82. }
  83. if (n==4)
  84. {cout << "End of program.\n";}
  85. if (n>=5||n<=0)
  86. {cout << "Not in range!!!\n";}
  87. return 0;
  88. }
  89.  
Success #stdin #stdout 0s 3144KB
stdin
Standard input is empty
stdout
Geometry Calculator

1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter 1,2,3, or 4: Not in range!!!