Overloaded function!

This is a discussion on Overloaded function! within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I was solving a problem of finding the biggest angle in the triangle . I first examined if ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    8

    Overloaded function!

    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;
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,177
    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).
    Last edited by grumpy; 03-05-2011 at 03:49 PM.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,414
    Quote Originally Posted by grumpy View Post
    ...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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    8
    Thank you both !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 03:25 AM
  3. Recursive function
    By WatchTower in forum C Programming
    Replies: 11
    Last Post: 07-15-2009, 07:42 AM
  4. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21