-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path01 Rectangle Menu.CPP
More file actions
54 lines (42 loc) · 1.23 KB
/
01 Rectangle Menu.CPP
File metadata and controls
54 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//Program displaying menu functionality: Rectangle Computations
#include <iostream.h>
#include <conio.h>
#include <math.h>
int getChoice() {
clrscr(); //Menu
cout << "Rectangle Menu: \n"
<< " 1. Area \n"
<< " 2. Perimeter \n"
<< " 3. Diagonal \n\n";
int choice;
do { //Choice Input and
cout << "Enter choice: "; //Error Checkig
cin >> choice;
} while (choice > 3 || choice < 1);
return choice;
}
void main() {
char again;
do {
float l=0, b=0;
again = 'n';
int choice = getChoice();
cout << "\n\nEnter length and breadth: ";
cin >> l >> b;
switch(choice) {
case 1: //Area
cout << "Area: " << l*b;
break;
case 2: //Perimeter
cout << "Perimeter: " << l+l+b+b;
break;
case 3: //Diagonal
cout << "Diagonal: " << sqrt(l*l+b*b);
break;
default:
cout << "Invalid Choice";
}
cout << "\n\nAgain? (Y/N) ";
cin >> again;
} while (again == 'y' || again == 'Y');
}