[Solved] Function returns a wrong number C++


You have two different ints which both happen to have the same name: The global rezultat declared at the top of the file, and the function parameter rezultat in the parameter list for function pop().

You pass the value of the global rezultat into pop(), then you assign a new value to the function parameter rezultat inside the function. When the function exits, the function parameter rezultat is gone. You didn’t assign a new value to the global rezultat, so it has the same value as it did before.

If you want to send the value of a variable from inside a function to the outside, use the return statement.

If you rename the global one to something else, that should clear up your confusion between the two.

Also, see @ForeverStudent’s excellent answer. He spotted a number of other issues that you’ll need to take a look at.

3

solved Function returns a wrong number C++