PDA

View Full Version : C++ void function help


frogdogbb
Oct7-05, 03:30 PM
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

frogdogbb
Oct7-05, 03:42 PM
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;
cout<<"max= " << max<<endl;
}
int main ()
{
void max (int x, int y, int z);
max(54, 27 ,35);

return 0;
}

saltydog
Oct7-05, 06:10 PM
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?

Brad_1234
Oct7-05, 07:19 PM
A void function is really just a subroutine. Specifying void as the return type means you dont 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 doesnt affect the original. But never assume a pass by val leaves the original untouched