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.
// "Area"
#include <iostream>
usingnamespace 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;
}