So my question is, what is the call? Is 0 the correct answer? And how do I call this myself on the compiler, without editing the void fi function since it was given to me as a constant function(or do you absolutely have to edit this?)
Yes, 0 is the answer. Also, you should have gotten errors when compiling, since the ending semi-colon is missing on line 15. Anyway, I added in cout's to show the results of each computation in the fi() function.
So is this right?
17/3=5.6, rounds down to 5
3+2=5
5/5, remainder is 0
So would my answer be a=0 and b=3? b remains unchanged since it is not pass by reference?
Also, if the math was more complex, what happens to pass by value and pass by reference values involved? For instance, if there was another line saying a1+=a2 and a2+=a1, would it use the original a1 and a2 values, or the ones edited within the code?
How can 0 be the answer if I need a value for a and b?
???? You have an a1 and a2, not a and b. Also, you can only return one variable from the function, which is the a2.
a1 = 17
a2 = 3
17 / 3 = 5
a2 + 2 = 5
5 goes into 5, one time, with nothing left over, which is what modulus is about
So, a2 is a zero, which is returned, which was your answer.
For your code to work properly, you have to get rid of the semi-colons on lines 2 and 4. Semi-colons end a statement, so lines 3 and 5 don't execute, only line 6 will.
Right now, I can't continue helping. It's almost 1:30 in the morning, and I'm headed for bed. Good luck..
I was told it's worded correctly as a question, so it may be purposefully wrong since I just started programming and we're expected to find errors. So would I say a and b are both 0?
The question exactly says
If A=17 and B=3, what will the values of a and b be after the call fi(a,b)?
a=?
b=?
That's what I'm trying to do here, that is just a practice question. I know that
I believe it's because a=17/3=5.66=5, and b remains unchanged because it was pass by value. I'm not sure about why I need an int for the y, or the cout "a:" part though.
The question exactly says:
What will the values of x and y be after the call fi(x,y)?
y=?
You don't need the y because you can think through the function and based on the code say that the y, whatever it is, will not change because the function takes that parameter by value. You don't even need to call the function, compile, or run any program.
However, you did try to call the function, incorrectly. It is a bit worrying that you seem to understand the parameters of a function, yet failed to call the function with correct syntax.
Notice that a1 is passed by reference, but a2 is passed by value. That means the final value of a2 is thrown away when the function is done. So the last two lines have no effect and you can think of the function as: