My code compiles and runs but it gives the number of the menu item I've chosen and is not assigning it a value ie.. square. Each time the variable shapeSelected comes up I need it to say the value of square, circle, etc., not 1, 2, or 3. Hope you understand what I'm trying to say. I know it's something simple and was hoping someone could help me where I'm messing up. Excuse my newbiness to the language, but I'm trying. Thanks for any help.
__________________________________________________ _
Code:/* Computes the area of a user selected shape (square, circle, or equilateral triangle) when given any number as a length for the Variable X which is also assigned by the user. */ #include<iostream> #include<cmath> using namespace std; int main () { double lengthX; double shapeArea; int shapeSelected; char square; char circle; char equilTriangle; cout << "This program will give you the area of the shape slected \n" << "(Circle, Square, or Equilateral Triangle) based on any given \n" << "length of the Variable X, which you, the user will provide. \n" << "\n" << "\n"; cout << "Please enter a length for the Variable X:"; cin >> lengthX; cout << "\n"; cout << "1 - Square" << endl; cout << "2 - Circle" << endl; cout << "3 - Equilateral Triangle" << endl; cout << "\n"; cout << "\n"; cout << "Please look at the above men and enter the number that \n" << "corresponds to the shape you would like to compute the \n" << "area of:"; cin >> shapeSelected; { if (shapeSelected == 1) square = shapeSelected; else if (shapeSelected == 2) circle = shapeSelected; else if (shapeSelected == 3) equilTriangle = shapeSelected; } // Calculates the area of chosen shape. { if (square == shapeSelected) shapeArea = (lengthX * lengthX); else if (circle == shapeSelected) shapeArea = (3.14) * (lengthX * lengthX); else if (equilTriangle == shapeSelected) shapeArea = ((sqrt(3)/4)) * (lengthX * lengthX); } cout << "The length you chose for Variable X is:" << lengthX; cout << "\n"; cout << "The shape you selected to get the area of was a/an:" << shapeSelected; cout << "\n"; cout << "The area of the" << shapeSelected << "is:" << shapeArea << endl; return 0; }



LinkBack URL
About LinkBacks


