Hello, i am working on something for school and have this much set up so far. I have completed the code to find the perimeter of the triangle using a class. When i run the program everything works well but after i input the three sides their is no answer returned. The program just ends. Please help. I would like to know why no answer is returned and how to fix it.
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
class Shape
{
public:
void shapeMenu();
float trianglePerimeter(float answer);
};
int main()
{
char letter;
float answerT;
Shape object;
cout << "Hello, welcome to the Perimenator 2.0.\n\nHere is a list of shapes that this program will solve for. The letters that must be entered are listed below.\n\n";
object.shapeMenu();
cout << endl << "Please enter the letter of the shape that you wish to find the perimeter of.";
cin >> letter;
object.trianglePerimeter(answerT);
}
void Shape:: shapeMenu()
{
cout << "1 : Enter 'T' for a Triangle" << endl;
cout << "2 : Enter 'E' for an Equalateral Triangle" << endl;
cout << "3 : Enter 'R' for a Rectangle" << endl;
cout << "4 : Enter 'P' for a Parallelogram" << endl;
cout << "5 : Enter 'Z' for a Trapezoid" << endl;
cout << "6 : Enter 'S' for a Square" << endl;
cout << "7 : Enter 'H' for a Rhombus" << endl;
cout << "8 : Enter 'K' for a Kite" << endl;
}
float Shape:: trianglePerimeter(float answer)
{
float a,b,c;
cout << "\nYou have chosen a triangle. Enter the three sides of the triangle.\n";
cout << "A =";
cin >> a;
cout << "\nB =";
cin >> b;
cout << "\nC =";
cin >> c;
answer = a + b + c;
return answer;
}
What exactly do you want to happen?
Your trianglePerimeter() function returns a float, but
when you call it: object.trianglePerimeter(answerT);
you never store this return value anywhere.
Also note that your input parameter (answerT) doesn't actually do anything.
Perhaps you meant to do something like this:
1 2 3 4
cout << endl << "Please enter the letter of the shape that you wish to find the perimeter of.";
cin >> letter;
float perimeter = object.trianglePerimeter(answerT);
cout << perimeter << endl;