Great job! Now your functions need to work like the problem asks you.
The two functions largest and smallest need to return int values:
CODE
int largest(int, int); //prototypes
int smallest();
When your functions return values back to main you need to assign it to a variable. For instance declare a variable of the type that your returning, in your case an int. Such as:
CODE
int maxNum;
int main()
{
maxNum = Largest(largest, numbers); //call
}
the number returned from the function is assigned to maxNum.
Then in your function, delete the cout where you display largest, and instead pass the number you want to send back to main:
CODE
return largest;
In effect what you are doing is making a copy of largest and putting it into the memory where maxNum is stored. One thing to note is that the variable names do not need to be the same. Once your program leaves your function, largest in that function is actually deleted, but since you returned the value back to main it is saved into maxNum. This way your functions can communicate back with main. Now that you have the largest number stored in maxNum, just print it there in main.
Your smallest function should do the same thing, I got you started up at the top with the prototype of what smallest should look like.
Your teacher is trying to teach you how to pass to and return values from functions and the way you did it kind of bypassed what he was trying to do by making these functions void and then printing from them. Learning how functions work is very very important, so try to figure out exactly what is happening when your program is running.
If you want shoot me an email, I have a file i could send you to reference. em1189@txstate.edu
This post has been edited by tortillaboy05: 3 Jul, 2008 - 08:35 AM