SHARE
TWEET

Untitled

a guest Dec 13th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     //Lets get the math out of the way
  11.  
  12.     int choice;
  13.     double h; //h = height
  14.     double r; //r = radius
  15.     double w; //w = width
  16.     double a; //a = answer
  17.     double b; //b = base
  18.     const double pi = 3.14159; //pre defined number
  19.     cout << setiosflags (ios::fixed | ios:: showpoint) << setprecision(2);
  20.  
  21.     // Asking basic questions, using switch #'s 1-4 , if it's above 4 or below 1 it's wrong.  4 ends the program.
  22.  
  23.     // PG. 237 is information for homework
  24.  
  25.     // Picking the choice
  26.  
  27.     cout << "Welcome to the Geometry Calculator\n\n";
  28.     cout << "Please select your choice!\n";
  29.     cout << "1. Area of a Circle\n";
  30.     cout << "2. Area of a Rectangle\n";
  31.     cout << "3. Area of a Triangle\n";
  32.     cout << "4. Quit the program\n\n";
  33.     cout << "Enter your choice here: ";
  34.     cin  >> choice;
  35.  
  36.     //Validating the choices
  37.  
  38.     while ((choice < 1) || (choice > 4))
  39.     {
  40.         cout << "The valid choices are 1 through 4.\n";
  41.         cout << "Please select a correct number choice: ";
  42.         cin  >> choice;
  43.     }
  44. //set changes based on choice
  45. switch (choice) {
  46. case 1: cout << "Enter the radius of the Circle: ";
  47. cin  >> r;
  48. a = pi * pow(r,2);
  49. cout << "The area of the Circle is: " << a << endl;
  50. break;
  51.  
  52. case 2: cout << "Enter the width of the Rectangle: ";
  53. cin  >> w;
  54. cout << "Enter the hight of the Rectangle: ";
  55. cin  >> h;
  56. a = w * h;
  57. cout << "The area of the Rectangle is: " << a << endl;
  58. break;
  59.  
  60. case 3: cout << "Enter the base of the Triangle: ";
  61. cin  >> b;
  62. cout << "Enter the height of the Triangle: ";
  63. cin  >> h;
  64. a = h * b / 2;
  65. cout << "The area of the Triangle is: " << a << endl;
  66. break;
  67.  
  68. case 4: break;
  69. }
  70.  
  71. // system ("PAUSE");
  72.  
  73. return 0;
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top