Monday, July 27, 2009

Parameters of a C++ Void Function?

When I try to compile my program I get an error that says there are too few parameters for my void function. I've tried changing the parameters a few times, but what it comes down to is that I just don't understand the rules of void function parameters. Can anyone explain them to me please?





If this helps, this is what I tried (each seperately):





void PrintAvg (float avg)


// avg being the variable defined as a calculation of an


// average done before the call for the PrintAvg function


// and I did make sure that it was declared as a float just


// in case I was making a typing error


void PrintAvg (float)


void PrintAvg (avg)

Parameters of a C++ Void Function?
Your problem is very unclear,


1. How you are calling PrintAvg(float avg)





your call to this function is like following








PrintAvg(10.56);





if you call your function like above you cant get any error.


One more thing have you declared it's prototype in main() or before main(), if not, define it like that





void PrintAvg(float);
Reply:wat is the funtion u r using that makes the difference in parameters


how did u called that


better post entire code
Reply:When you create a function:





void PrintAvg (float avg)


{


//code goes here


}





When you want to USE a function





PrintAvg(/*whatever number you want*/);








You give a function as many parameters as you want, for example:





void PrintAvg(float avg, float num1, float num2)


{


//code goes here


}





that function takes 3 parameters. When you use that function, you would type





PrintAvg(3.5, 8.76, 4.32);





See, you type 3 numbers into that function because it had 3 parameters


No comments:

Post a Comment