-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaOfShapes.cpp
More file actions
48 lines (41 loc) · 1.18 KB
/
Copy pathAreaOfShapes.cpp
File metadata and controls
48 lines (41 loc) · 1.18 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
#include <iostream>
using namespace std;
double CalculateArea(int choice, double dimensions[]){
double area;
switch(choice){
case 1:
area = dimensions [0] * dimensions[0];
break;
case 2:
area = 0.5 * dimensions[0] * dimensions[1]; //Triangle
break;
case 3:
area = dimensions[0] * dimensions [1]; // Rectangle
break;
default:
area =0;
}
return area;
}
int main(){
int choice;
double dimensions[2];
string shapes [] = {"Square", "Triangle", "Rectangle", "Quit"};
while(true){
cout << "Choose a shape to calculate its area :" << endl;
for(int i = 0; i < 4; i++){
cout << i + 1 << "." << shapes[i] << endl;
}
cin >> choice;
if (choice == 4){
return 0;
}
cout << "Enter the dimendions of the " << shapes [choice - 1] << "." << endl;
for (int i = 0; i < (choice == 1 ? 1 : 2); i++){
cin >> dimensions[i];
}
double area = CalculateArea(choice, dimensions);
cout << "The area of a " << shapes [choice - 1] << " is: " << area << endl;
}
return 0;
}