Your issue here seems to be that you don't really understand the difference between passing as a reference and as a value.
If you take a closer look at your if statement you'll see what I'm trying to say:
if (getInput(userInput)) !=0
What this actually means is: If, the value returned from getInput, (With the value userInputPassed to it))//end conditional) Does not equal zero{
//Do stuff
}
When you pass any item by reference, it as as though you are performing actions directly on that item.
Example:
At this point in your code:
int getInput(int &userInput){
int menuSel;
cin >> menuSel;
userInput = menuSel;
return menuSel;
}
What you are saying to the compiler is "I am passing the reference (the memory location) of userInput as an int to the getInput function, I am expecting it to return an int. However, since you are passing by reference, there is no need to return anything, as any changes you make to userInput are not effected by the scope of the function and will appear back in int main. So in this code you are taking a value (which is empty) declaring an empty variable cin for the empty variable, set the variable you passed to the variable, and then returning the value to something that is discarding it (since you didn't do something like x=getInput(userInput) the value returned just gets discarded and returned to the heap.)
I've made 2 revisions to your code for you. Revision 1 is a pretty simple one. I simply 'fixed' what was immediately 'wrong' with your code, changed a few things around, and used pass by value rather than pass by reference.
Revision 1 is available here: https://ideone.com/CjUac
Revision 2 is most likely what you're looking for, it keeps the code very similar to the way that you have it using a reference pass rather than a value:
https://ideone.com/QD5ZF -- Ignore the selection number in this one, as it's an uninitialized variable.
In this revision you'll see I did one thing to make you sure you understand exactly what's going on. In the PBR (pass by reference) function of getInput I renamed "userInput" to userInput2. I did that to show you that no matter WHAT name you give something inside a function, if it's passed by reference it still references the value that was passed to it.
I should also note that I always use function prototypes in my code (the void (int&); before int main) because I really like knowing what my main is doing before I start working on functions, so coding them in that order makes the most logical sense to me, so my prototypes allow me to call a function before I specify EXACTLY what it does. When it's called, the program will seek out the function and determine how to proceed.
Good luck with your project and if you should need any more help, be sure to let me know :).
Edit 3: And just to be super nice, I'll walk you through the variable pass to function in revision 1:
You are declaring a variable called menuSel on line 17 and not setting it to anything.
On line 19 you are using the getInput function to pass the value that exists in menuSel to the getInput function. This is dangerous (uninitialized variables are bad, kay?) where the value that is stored in it, is turned into the variable "userInput" which is scoped for use only in the getInput function. When getInput ends, userInput disappears in this case. The value that will be returned will not be set to anything, and will unfortunately be lost by this program. To solve that you could change line 19 from:
getInput(menuSel);
to
menuSel= getInput(menuSel);
This would set the value in menuSel to whatever the user input in the getInput function.
Final edit: Things to take away from this:
When passing a value by reference, you only need & in the definition of the function, not where the item is passed.
If you are trying to set 1 variable, and you're passing by reference, you can probably use type void
If you are still having trouble or if I confused you with my HUGE explanation, shoot me a mail and I'll explain. I check my mail about 1-2 times a day