Issue with minMax() function and paramater passing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FAUPrideBaby
    New Member
    • Jan 2008
    • 2

    Issue with minMax() function and paramater passing

    Question:
    Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are set by the function to the largest and smallest of the values of the first three parameters.

    The function does not return a value.

    The function can be used as follows:

    ******int a=31, b=5, c=19, big, small;
    ******minMax(a, b,c,&big,&small );
    ************/* big is now 31 */
    ************/* small is now 5 */

    My Answer:

    void minMax(int a,int b, int c, int *big, int *small){
    if(a>b && a>c){
    a= *big;
    }
    if(b>a && b>c){
    b= *big;
    }
    else if(c>a && c>b){
    c= *big;
    }
    else if(a<b && a<c){
    a= *small;
    }
    else if(b<a && b<c){
    b= *small;
    }
    else{
    c= *small;
    }
    }

    Errors:

    Remarks:
    *****⇒*****Your function did not change the values of class=code>big or
    Don't have to give answers I'm fine with suggestions as how to solve this plz help!
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    I fail to see your question. Also, your post is somewhat troublesome to understand. The code should be placed in CODE tags. And I'm not sure what's going in that Errors/Remarks portion at the end.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Changing the arguments a,b and c inside the function is pointless unless you use them inside the funciton. These are copies of the ints used on the call.

      These copies are destroyed when the function returns. Hence, the calling function does not see the change.

      To change a variable in the calling funciton, you need to pass the address of the variable to the function.

      Comment

      Working...