Thread: help with function

  1. #1
    Registered User
    Join Date
    Nov 2014
    Posts
    4

    help with function

    excuse me sir,can you help me with my c++ problem

    Code:
    //calculate bandwidth using maximum-minimum
    #include<iostream>
    using namespace std;
    
    
    int maximumValue( int , int , int , int , int);//function prototype
    int minimumValue( int , int , int , int , int );//function prototype
    int bandwidth;
    
    
    int main()
    {
        int v , w , x , y , z ;
    
    
       
        
        cout<<" enter five integers "<<"\n\n";
        cin>> v >> w >> x >> y >> z ;
        cout<<"\n\n"<<" the maximum value is " <<maximumValue(v,w,x,y,z)<<"\n\n";
        cout<<"\n\n"<<" the minumum value is " <<minimumValue(v,w,x,y,z)<<"\n\n";
        cout<<"\n\n"<<" the bandwidth is "<<bandwidth<<maximumValue-minimumValue<<"\n\n";
        
        cout<<endl;
        return 0;
        
        system("pause");
        
        
    }
    
    
    int maximumValue( int a , int b , int c , int d , int e)
    
    
    {
        if (a>b && a>c && a>d && a>e)
         return a;
        else if (b>a && b>c && b>d && b>e)
         return b;
        else if (c>a && c>b && c>d && c>e)
         return c;
        else if (d>a && d>b && d>c && d>e)
         return d;
        else
         return e;
    
    
    }
        
    
    
    int minimumValue ( int a , int b , int c , int d , int e )
    
    
    {
        if (a<b && a<c && a<d && a<e)
         return a;
        else if (b<a && b<c && b<d && b<e)
         return b;
        else if (c<a && c<b && c<d && c<e)
         return c;
        else if (d<a && d<b && d<c && d<e)
         return d;
        else
         return e;
    
    
    }


    thanks for your time

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to ask a question about what you're having difficulties with.
    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.

  3. #3
    Registered User
    Join Date
    Nov 2014
    Posts
    4
    sorry.
    i cant manage to calculate the bandwith.
    im searched through google but cant help myself anymore
    btw this is the error code
    19 65 C:\Users\unk\Desktop\maximum minimum.cpp [Error] ISO C++ forbids using pointer to a function in subtraction [-fpermissive]

  4. #4
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    Code:
        cout<<"\n\n"<<" the bandwidth is "<<bandwidth<<maximumValue-minimumValue<<"\n\n";
    This line needs to be changed to this:
    Code:
    bandwidth = maximumValue(v,w,x,y,z) - minimumValue(v,w,x,y,z);
    cout << "\n\n" << " the bandwidth is " << bandwidth << "\n"
    using the name 'maximumValue' (without parenthesis) refers to a pointer to the function maximumValue. Which is what the error is telling you, you're trying to subtract one function pointer from another which won't work. Using the parenthesis, like maximumValue() is how you actually "call" the function and use it.

  5. #5
    Registered User
    Join Date
    Nov 2014
    Posts
    4
    thanks for your time @Elysia and @nonpuz

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, to be a exact, a function must be called, and when it is called, you must specify its arguments. If it takes no arguments, then you must specify an empty parameter list ().
    A result computed by a function must stored in a variable or it is discarded. Simply re-typing the function's name will not call up its result.
    Typing a function without its parameter list will result in a pointer to the function, which is not what you want.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function Prototype, Function Call, and Function definition
    By dmcarpenter in forum C Programming
    Replies: 9
    Last Post: 04-09-2013, 03:29 AM
  2. Replies: 13
    Last Post: 03-20-2012, 08:29 AM
  3. Replies: 2
    Last Post: 02-26-2009, 11:48 PM
  4. Print function: sending a function.. through a function?
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 11-05-2008, 05:03 PM
  5. Replies: 9
    Last Post: 01-02-2007, 04:22 PM