Guest User

Untitled

a guest
Feb 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[]) {
  7.     int input = 0, width, height, radius;
  8.     cout << "Please enter a number 1-4: ";
  9.     cin >> input;
  10.     if((input > 4) || (input < 1)) {
  11.         cout << "Error: You may not input a number greater than 4 or less than 1." << endl;
  12.         return(1);
  13.     }
  14.     switch(input) {
  15.         case 1:
  16.             radius = 0;
  17.             cout << "Please enter the radius of your circle: ";
  18.             cin >> radius;
  19.             if(radius < 1) {
  20.                 cout << "Error: You may not input a number less than 1 for the radius." << endl;
  21.                 return(2);
  22.             }
  23.             cout << "The area of your circle is " << 3.14159 * pow(radius, 2) << " units." << endl;
  24.             break;
  25.         case 2:
  26.             width = height = 0;
  27.             cout << "Please enter the width of your rectangle: ";
  28.             cin >> width;
  29.             if(width < 1) {
  30.                 cout << "Error: You may not input a number less than 1 for the width." << endl;
  31.                 return(3);
  32.             }
  33.             cout << "Please enter the height of your rectangle: ";
  34.             cin >> height;
  35.             while(height < 1) {
  36.                 cout << "Error: You may not input a number less than 1 for the height." << endl;
  37.                 return(4);
  38.             }
  39.             cout << "The area of your rectangle is " << width * height << " units." << endl;
  40.             break;
  41.         case 3:
  42.             width = height = 0;
  43.             cout << "Please enter the base of your rectangle: ";
  44.             cin >> width;
  45.             if(width < 1) {
  46.                 cout << "Error: You may not input a number less than 1 for the base." << endl;
  47.                 return(5);
  48.             }
  49.             cout << "Please enter the height of your rectangle: ";
  50.             cin >> height;
  51.             while(height < 1) {
  52.                 cout << "Error: You may not input a number less than 1 for the height." << endl;
  53.                 return(6);
  54.             }
  55.             cout << "The area of your rectangle is " << width * height * 0.5 << " units." << endl;
  56.             break;
  57.         case 4:
  58.             return(0);
  59.     }  
  60. }
Add Comment
Please, Sign In to add comment