Writing a void function to find the maximum of three integers

  • Context: C/C++ 
  • Thread starter Thread starter frogdogbb
  • Start date Start date
  • Tags Tags
    C++ Function
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 27K views
frogdogbb
Messages
45
Reaction score
0
I have to answer a homework problem due today that I am not sure how to do the problem reads.
"Write a program that calls a void type function to find the maximum of three given integer numbers"
We use visual studio.net, any help would be appreciated and I would like to be able to compile it and run the program so I can figure out how it works.
Thanks
 
Physics news on Phys.org
never mind

I got it thanks anyway
// 7.3.cpp : Defines the entry point for the console application.
#include <iostream>
using namespace std;
void max(int x, int y, int z)
{
int max;
max=x;
if(y>max)max=y;
if(z>max)max=z;
count<<"max= " << max<<endl;
}
int main ()
{
void max (int x, int y, int z);
max(54, 27 ,35);

return 0;
}
 
I got a problem with that: Your problem said "find" the maximum value. Well, just printing it to the screen is not "finding it" as far as I'm concerned. You know, now if you "stored" it to some variable name, then to me that would be considered "finding it". Suppose that might be a good thread in some "philosophy of computation" forum. Just what does "finding" it really mean?
 
Last edited:
A void function is really just a subroutine. Specifying void as the return type means you don't include the final "return 0;" or whatever return value.

When you call a function, keep in mind passing by value or passing by reference can sometimes affect your original value.

If youre calling a value type, like Int, Char, Long etc, pass by val means your value sits on the stack and gets copied for use, so the copy doesn't affect the original. But never assume a pass by val leaves the original untouched