• 03-05-2011
Coca cola
Hi everyone, I was solving a problem of finding the biggest angle in the triangle . I first examined if there is a triangle with entered numbers and then calculated angles, found maximum and express it in degrees,minutes and seconds. But it says in line 22 that there is a mistake.(It's written that function is overloaded).In lines 23,24,25 it shows also mistakes.

Code:

``` #include<iostream> #include<cmath> using namespace std; int main(){     double a,b,c;     cout<<"Enter a,b,c :";     cin>>a>>b>>c;     if(a>0 && b>0 && c>0 && ((a+b<c) || (c+b<a) || (a+c<b))){     double gama=acos((a*a+b*b-c*c)/2*a*b);     double alfa=acos((b*b+c*c-a*a)/2*b*c);     double beta=acos((a*a+c*c-b*b)/2*a*c);     double pi=4*atan(double(1));     gama*=(180/pi);     alfa*=(180/pi);     beta*=(180/pi);     if((alfa>beta)&&(alfa>gama))     double max=alfa;     else if((beta>alfa)&&(beta>gama))     double max=beta;     else if((gama>beta)&&(gama>alfa))     double max=gama;     max*=3600;     int degrees=int(max/3600);     int minutes=int(((max)-3600*(degrees))/60);     int seconds=int(max-3600*seconds-60*minutes);     cout<<"The biggest angle : "<<degrees<<" degrees"<<", "<<minutes<<"minutes"<<"i"<<seconds<<"seconds"<<endl;     }     else cout<<"It doesn't exist";     return 0; }```
• 03-05-2011
grumpy
Your code has multiple definitions of max. Change this
Code:

```    if((alfa>beta)&&(alfa>gama))     double max=alfa;     else if((beta>alfa)&&(beta>gama))     double max=beta;     else if((gama>beta)&&(gama>alfa))     double max=gama;```
to
Code:

```    double max;     if((alfa>beta)&&(alfa>gama))         max=alfa;     else if((beta>alfa)&&(beta>gama))         max=beta;     else if((gama>beta)&&(gama>alfa))         max=gama;```
It also pays to learn the practice of indenting code - it makes coding problems easier to find.

If that doesn't fix your problem, rename "max" to something else. Although it is non-standard, the standard headers shipped with some compilers (notably some versions of Microsoft compilers) do declare a function named max(), so will give problems with your code. The standard specifies that the <algorithm> header supplies a templated std::max() function, and some other standard headers might #include that header (another quaint quirk of some implementations of the standard libraries).
• 03-06-2011
Elysia
Quote:

Originally Posted by grumpy
...If that doesn't fix your problem, rename "max" to something else. Although it is non-standard, the standard headers shipped with some compilers (notably some versions of Microsoft compilers) do declare a function named max(), so will give problems with your code. The standard specifies that the <algorithm> header supplies a templated std::max() function, and some other standard headers might #include that header (another quaint quirk of some implementations of the standard libraries).

Which is why I do not advocate using using namespace std.
Hmm. I might just write an article about that one.
• 03-06-2011
Coca cola
Thank you both !