Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main(int argc, char *argv[]) {
- int input = 0, width, height, radius;
- cout << "Please enter a number 1-4: ";
- cin >> input;
- if((input > 4) || (input < 1)) {
- cout << "Error: You may not input a number greater than 4 or less than 1." << endl;
- return(1);
- }
- switch(input) {
- case 1:
- radius = 0;
- cout << "Please enter the radius of your circle: ";
- cin >> radius;
- if(radius < 1) {
- cout << "Error: You may not input a number less than 1 for the radius." << endl;
- return(2);
- }
- cout << "The area of your circle is " << 3.14159 * pow(radius, 2) << " units." << endl;
- break;
- case 2:
- width = height = 0;
- cout << "Please enter the width of your rectangle: ";
- cin >> width;
- if(width < 1) {
- cout << "Error: You may not input a number less than 1 for the width." << endl;
- return(3);
- }
- cout << "Please enter the height of your rectangle: ";
- cin >> height;
- while(height < 1) {
- cout << "Error: You may not input a number less than 1 for the height." << endl;
- return(4);
- }
- cout << "The area of your rectangle is " << width * height << " units." << endl;
- break;
- case 3:
- width = height = 0;
- cout << "Please enter the base of your rectangle: ";
- cin >> width;
- if(width < 1) {
- cout << "Error: You may not input a number less than 1 for the base." << endl;
- return(5);
- }
- cout << "Please enter the height of your rectangle: ";
- cin >> height;
- while(height < 1) {
- cout << "Error: You may not input a number less than 1 for the height." << endl;
- return(6);
- }
- cout << "The area of your rectangle is " << width * height * 0.5 << " units." << endl;
- break;
- case 4:
- return(0);
- }
- }
Add Comment
Please, Sign In to add comment