Problem with functions and triangle sides

I'm trying to make a function that assigns numbers to types of triangles when given 3 numbers. Ex: 3=equilateral, 2=isosceles, etc. But when I'm trying to call the functions into my main() it doesn't seem to work. Maybe I just don't understand functions enough :S

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

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
inline void keep_window_open(){char ch; cin>>ch;}

double triangle_kind(double a,double b,double c){
    double triangle_kind;
       if(a+b>c&&a+c>b&&b+c>a)
            triangle_kind=0;
       else if(a==b&&b==c&&a==c)
            triangle_kind=3;
       else if(a==b||a==c||b==c)
            triangle_kind=2;
       else
           triangle_kind=-1;       
}

int main()
{
    double a,b,c;
    cout<<"Please enter three sides of a triangle (can have decimal values): \n";
    cin>>a>>b>>c;
    double triangle_kind;
                 if(triangle_kind=0)
                      cout<<"This triangle is scalene.\n";
                 else if(triangle_kind=3)
                      cout<<"This triangle is equilateral.\n";
                 else if(triangle_kind=2)
                      cout<<"This triangle is isosceles.\n";
                 else if(triangle_kind=-1)
                      cout<<"This is not a triangle!\n";
    system("Pause");
}


Everything is coming out as "Equilateral".

Any help would be appreciated.
Your code doesn't compile because the function triangle_kind doesn't return a value. It's always good to post the actual code you're using.

1
2
3
4
5
6
7
8
9
double triangle_kind;
                 if(triangle_kind=0)
                      cout<<"This triangle is scalene.\n";
                 else if(triangle_kind=3)
                      cout<<"This triangle is equilateral.\n";
                 else if(triangle_kind=2)
                      cout<<"This triangle is isosceles.\n";
                 else if(triangle_kind=-1)
                      cout<<"This is not a triangle!\n";


if (triangle_kind=0)

is equivalent to:

1
2
triangle_kind = 0;
if ( triangle_kind != 0) 


To check equality you should use the == operator. Your compiler is probably giving you a warning for this that you're not paying attention to.

You never call the triangle_kind function.

Topic archived. No new replies allowed.