My program complies but won't output what triangle it is

#include <iostream>
using namespace std ;
enum triangleType { scalene , isosceles , equilateral , noTriangle } ;
void getlength (double & side1, double & side2, double & side3);
triangleType triangle ( double , double , double ) ;
void displayResults ( triangleType, int shape) ;
int main()
{
double side1, side2, side3;
int shape ;
getlength (side1, side2, side3);
shape = triangle ( side1, side2, side3) ;
void displayResults ( int shape ) ;


system ("pause");
return 0 ;
}
void getlength (double & side1, double & side2, double & side3)
{
cout << "Side 1 length: " ;
cin >> side1 ;
cout << "Side 2 length: " ;
cin >> side2 ;
cout << "Side 3 length: " ;
cin >> side3;
}
triangleType triangle ( double side1 , double side2 , double side3 )
{
triangleType shape ;
if ( side1 > side2 + side3 || side2 > side1 + side3 || side3 > side1 + side2 )
shape = noTriangle ;
else if ( side1 == side2 && side1 == side3 && side2 == side3 )
shape = equilateral ;
else if ( side1 != side2 && side1 != side3 && side2 != side3 )
shape = scalene ;
else if (side1 == side2 || side1 == side3 || side2 == side3 )
shape = isosceles ;
return shape ;
}
void displayResults ( triangleType, int shape)
{
switch (shape)
{
case 0:
cout << "Triangle Shape: Scalene " << endl ;
break ;
case 1:
cout << "Triangle Shape: Isosceles " << endl ;
break ;
case 2:
cout << "Triangle Shape: Equilateral " << endl ;
break ;
case 3:
cout << "Triangle Shape: No Triangle " << endl ;
break ;
}
}
First please use the code tags.

Here, this is better.

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
50
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std ;
enum triangleType { scalene , isosceles , equilateral , noTriangle } ;
void getlength (double & side1, double & side2, double & side3);
triangleType triangle ( double , double , double ) ;
void displayResults ( triangleType, int shape) ;
int main()
{
double side1, side2, side3;
int shape ;
getlength (side1, side2, side3);
shape = triangle ( side1, side2, side3) ;
void displayResults ( int shape ) ;


system ("pause");
return 0 ;
}
void getlength (double & side1, double & side2, double & side3)
{
cout << "Side 1 length: " ;
cin >> side1 ;
cout << "Side 2 length: " ;
cin >> side2 ;
cout << "Side 3 length: " ;
cin >> side3;
}
triangleType triangle ( double side1 , double side2 , double side3 )
{
triangleType shape ;
if ( side1 > side2 + side3 || side2 > side1 + side3 || side3 > side1 + side2 )
shape = noTriangle ;
else if ( side1 == side2 && side1 == side3 && side2 == side3 )
shape = equilateral ;
else if ( side1 != side2 && side1 != side3 && side2 != side3 )
shape = scalene ;
else if (side1 == side2 || side1 == side3 || side2 == side3 )
shape = isosceles ;
return shape ;
}
void displayResults ( triangleType, int shape)
{
switch (shape)
{
case 0:
cout << "Triangle Shape: Scalene " << endl ;
break ;
case 1:
cout << "Triangle Shape: Isosceles " << endl ;
break ;
case 2:
cout << "Triangle Shape: Equilateral " << endl ;
break ;
case 3:
cout << "Triangle Shape: No Triangle " << endl ;
break ;
}
} 


ok the problems I see are:

*Line 6 you have two variables for the function displayResults but in your main function on line 13 you only pass one variable called "shape" to the displayResults function. I removed the first variable and the program worked fine for me.

*Also, on line 13 in your main function, you have a void in front of the displayResults function which is incorrect. When you call a function after it's been declared you don't include the type. So remove the void and it will work correctly.

*Line 41 is related to the first bullet I mentioned. Remove the triangleType parameter from the function prototype and the program will work correctly.
Last edited on
Topic archived. No new replies allowed.