Classes help please

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace 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;
}
Your only probably seems to be that when you call the the trianglePerimeter function is that you don't actually cout the returned value.
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;


Last edited on
thanks for the help guys. that fixed it Ganado thank you very much. that stopped a lot of frustration, shoulda thought of that myself :). thanks.
Topic archived. No new replies allowed.