| | |
User-Defined Function - setup right?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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
What is the output of the following function calls?
defaultParam(6) ;
defaultParam(3, 4) ;
defaultParam(3, 0, 2.8) ;
Here is my code:
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:?
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
c++ Syntax (Toggle Plain Text)
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:
c++ Syntax (Toggle Plain Text)
#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:?
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.
-Edsger Dijkstra
-Edsger Dijkstra
Of course not....
What's u, v, and z?
Now what's
Now what's
Are the lack of parentheses in the original equations throwing you? If so, prime reasong to paranthesize everything!
•
•
•
•
c++ Syntax (Toggle Plain Text)
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 ; }
defaultParam(6) ;
Now what's
u + (( 2 * v ) + z )? Replace u with this value -- as an integerNow what's
u + (v * z), also as an integer after calculating.Are the lack of parentheses in the original equations throwing you? If so, prime reasong to paranthesize everything!
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- User-defined functions (C++)
- User-Defined Function - part 2 (C++)
- error in user defined string class (C++)
- using(STL)function object (bind2nd) with a user defined function object (C++)
Other Threads in the C++ Forum
- Previous Thread: MySQL++ query question
- Next Thread: 80-bit long doubles
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






