We haven't really covered pointers but have been learning about passing by reference (the &
pointer will be covered later). In an exercise, we were asked to write a small question game that would pass values in a simple one class main
program between its functions to get things done.
If we have a hierarchy where main
calls 2 functions: function askNum
, and function giveStats
, with askNum
having a host of functions inside (one on the lower level being checkIfRight
). I need to call giveStats
which would basically tell the user how well they've guessed over a set of questions.
I am glossing over the details because I want to focus on the fact that we can't use value returning functions or global variables. So I have to figure out a way to count the number of guesses correct within checkIfRight
and send that info back up the hierarchy of functions to giveStats
.
I am not sure how to call it though. I have most of the code figured out for this game and implemented simple pass by reference on functions in the same hierarchy, I am confused about having a function outside basically call it. So would there be a variable in main called numCorrect
and giveStats
would call it after askNum
modifies it?