Using characters to make selections

I am trying to figure out how to use letters to make MENU selections instead of numbers. Also, I cannot figure out how to keep the program running indefinitely, essentially going back to the beginning after an area has been found.

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  // "Area"
#include <iostream>
using namespace std;

float result;

int rectangle()
{
float height, width;
cout << "\nYou have chosen rectangle.\nPlease enter height and width : ";
cin >> height >> width;
result = height * width;
cout << "The area of the rectangle is : " << result << endl;
}

int circle()
{
float radius;
cout << "\nYou have chosen circle\nPlease enter radius : ";
cin >> radius;
result = 3.14 * radius * radius;
cout << "The area of the circle is : " << result << endl;
}

int triangle()
{
float breadth, height;
cout << "\nYou have choosen triangle\nPlease enter breadth and height : ";
cin >> breadth >> height;
result = breadth * height * 0.5;
cout << "The area of the triangle is : " << result << endl;
}

int square()
{
float side;
cout << "\nYou have chosen square\nPlease enter side : ";
cin >> side;
result = side * side;
cout << "The area of the square is : " << result << endl;
}

int main()

{
int choice;
cout << "\n\n************* MENU ***************" << endl;
cout << "\tR. Rectangle\n\tC. Circle\n\tT. Triangle\n\tS. Square\n\tX. Exit\nEnter a letter to perform actions\n";
cin >> choice;

switch (choice)
{
case 1:
rectangle();
break;

case 2:
circle();
break;

case 3:
triangle();
break;

case 4:
square();
break;

case 5:
cout << "\nAdios Amigo !" << endl;

return 0;
break;

default:
cout << "ERROR : Invalid input !" << endl;
break;
}


return 0;
}
Last edited on
Topic archived. No new replies allowed.