Skip to content

Instantly share code, notes, and snippets.

Created August 5, 2014 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6e0dd7c29da634a41aac to your computer and use it in GitHub Desktop.
Save anonymous/6e0dd7c29da634a41aac to your computer and use it in GitHub Desktop.
#include <iostream>
#include <limits>
#include <iomanip>
using std::cout;
using std::endl;
using std::cin;
int menu()
{
double rec, square, circle, sum;
char choice;
cout << "\n Choose which Area you want to find:\n"
<< "1) Area of rectangle.\n"
<< "2) Area of Square.\n"
<< "3) Area of Circle.\n"
<< "Choose any of the above, or enter 4 to quit." << endl;
cin >> choice;
cin.ignore(std::numeric_limits<int>::max(), '\n');
return choice;
}
void choice1()
{
double l, b, areaofrectangle;
cout << "enter lengeth of rectangle : ";
cin >> l;
cout << "enter breadth : ";
cin >> b;
areaofrectangle = l*b;
cout << "Area of rectangle is : " << areaofrectangle << endl;
}
void choice2()
{
double l, areaofsquare;
cout << " enter length is square : ";
cin >> l;
areaofsquare = l*l;
cout << "Area of square is : " << areaofsquare << endl;
}
void choice3()
{
double r, areaofcircle;
const double pi = 3.14159;
cout << "enter radius of circle : ";
cin >> r;
areaofcircle = pi*r*r;
cout << "area of circle is : " << areaofcircle;
}
int main()
{
char choice;
do
{
choice = menu();
switch (choice)
{
case '1':
choice1();
break;
case '2':
choice2();
break;
case '3':
choice3();
break;
case '4':
break;
default:
cout << "Try entering a number that's\
actually on the screen." << endl;
break;
}
} while (choice != '4');
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment