Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- int main()
- {
- //Lets get the math out of the way
- int choice;
- double h; //h = height
- double r; //r = radius
- double w; //w = width
- double a; //a = answer
- double b; //b = base
- const double pi = 3.14159; //pre defined number
- cout << setiosflags (ios::fixed | ios:: showpoint) << setprecision(2);
- // Asking basic questions, using switch #'s 1-4 , if it's above 4 or below 1 it's wrong. 4 ends the program.
- // PG. 237 is information for homework
- // Picking the choice
- cout << "Welcome to the Geometry Calculator\n\n";
- cout << "Please select your choice!\n";
- cout << "1. Area of a Circle\n";
- cout << "2. Area of a Rectangle\n";
- cout << "3. Area of a Triangle\n";
- cout << "4. Quit the program\n\n";
- cout << "Enter your choice here: ";
- cin >> choice;
- //Validating the choices
- while ((choice < 1) || (choice > 4))
- {
- cout << "The valid choices are 1 through 4.\n";
- cout << "Please select a correct number choice: ";
- cin >> choice;
- }
- //set changes based on choice
- switch (choice) {
- case 1: cout << "Enter the radius of the Circle: ";
- cin >> r;
- a = pi * pow(r,2);
- cout << "The area of the Circle is: " << a << endl;
- break;
- case 2: cout << "Enter the width of the Rectangle: ";
- cin >> w;
- cout << "Enter the hight of the Rectangle: ";
- cin >> h;
- a = w * h;
- cout << "The area of the Rectangle is: " << a << endl;
- break;
- case 3: cout << "Enter the base of the Triangle: ";
- cin >> b;
- cout << "Enter the height of the Triangle: ";
- cin >> h;
- a = h * b / 2;
- cout << "The area of the Triangle is: " << a << endl;
- break;
- case 4: break;
- }
- // system ("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment