Hey all,
I'm doing hw, and I did a desk-check for this program and got completely different answers than that of the computer when the program was put into the compiler.
The question says to consider the function defaultParam
void defaultParam ( int u , int v = 5 , double z = 3.2 )
{
int a ;
u = u + static_cast<int>( 2 * v + z ) ;
a = u + v * z ;
cout << "a = " << a << endl ;
}
What is the output of the following function calls?
defaultParam(6) ;
defaultParam(3, 4) ;
defaultParam(3, 0, 2.8) ;
Here is my code:
#include <iostream>
using namespace std ;
void defaultParam ( int u , int v = 5 , double z = 3.2 ) ;
int main ()
{
defaultParam(6) ;
defaultParam(3 , 4) ;
defaultParam(3 , 0 , 2.8) ;
return 0 ;
}
void defaultParam ( int u , int v , double z )
{
int a ;
u = u + static_cast<int>( 2 * v + z ) ;
a = u + v * z ;
cout << "a = " << a << endl ;
}
My output from this code is:
a = 35
a = 26
a = 5
Press any key to continue . . .
but when I did the desk-checking I got:
50
54.2
3
Is my program setup to give me the correct results? Or am I right? Or neither :mrgreen:?