Okay, i have written a code to figure out the area of all different shapes but i can't get it past hte pasrt where the client chooses what they want to find the area of.
this is my code:

``````#include <iostream>
#include <cmath>
using namespace std;

int getChoice();
int circle();
int rectangle();
int trapazoid();
int triangle();
int parallelogram();

int main()
{

int choice;
do{
choice = getChoice();
if ( choice == 1 ) circle();
else if ( choice == 2 ) rectangle();
if ( choice > 6 || choice < 1 )
cout << "\nPlease enter a valid number.\n"<<endl;
else if ( choice == 3 ) trapazoid();
if ( choice == 4 ) triangle();
else if (choice == 5) parallelogram();
} while ( choice != 6);
}

int getChoice()
{

int x;
cout << "                ||~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~||" << endl;
cout << "                ||      Area Of 2-D Shapes        ||" << endl;
cout << "                ||---------------------------------------------||" << endl;
cout << "                || Press 1 to find the area of a circle        ||" << endl;
cout << "                || Press 2 to find the area of a rectangle     ||" << endl;
cout << "                || Press 3 to find the area of a trapazoid     ||" << endl;
cout << "                || Press 4 to find the area of a triangle      ||" << endl;
cout << "                || Press 5 to find the area of a parallelogram ||" << endl;
cout << "                || Press 6 to quit                             ||" << endl;
cout << "                ||                                             ||" << endl;
cout << "                ||~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~||\n" << endl;
cin >> x;
}

int circle()

{

double r;
cout << "\nEnter Radious of the circle = ";
cin >> r;
cout << "\nArea = " <<answer1;

}

int rectangle()

{

double w;
double h;
cout << "\nEnter the width of the rectangle = ";
cin >> w;
cout << "\nEnter the height of the rectangle = ";
cin >> h;
cout << "\nArea = " << answer2;

}

int trapazoid()

{

double h;
double b1;
double b2;
cout << "\nEnter the hight of the trapezoid: ";
cin >> h;
cout << "\nEnter the bottom base of the Trapezoid: ";
cin >> b1;
cout << "\nEnter the top base of the Trapezoid: ";
cin >> b2;
answer3 = 0.5 * h * (b1 + b2);
cout << "\nArea = " << answer3;

}

int triangle()

{

double h;
double b;
cout << "\nEnter the base of the triangle: ";
cin >> b;
cout << "\nEnter the height of the triangle: ";
cin >> h;
answer4 = 0.5 * b * h;
cout << "\nArea = " << answer4;

}

int parallelogram()

{

double b;
double h;
cout << "\nEnter the base of the Parallelogram = ";
cin >> b;
cout << "\nEnter the height of the Parallelogram = ";
cin >> h;
cout << "\nArea = " << answer5;

}``````
3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by toko

Your getChoice( ) function gets user input, but does not pass it back to main( ).

``````cout << "\nPlease enter number for your choice: ";
cin >> x;
return x;    //add this so the choice gets sent back to main( )
}``````

Val