student question

This is a discussion on student question within the C++ Programming forums, part of the General Programming Boards category; I've got a program that has a main menu for the user to choose from in main. each choice calls ...

student question

I've got a program that has a main menu for the user to choose from in main. each choice calls a different function. the first choice in main is to enter information, it calls a function getinfo. It works but how do I go back to main everytime I finish a function so the user can pick another.
choices (and functions)
1. enter info
2. update info
3. calculate
4. display
5. exit

Usually you would use a class to store related information and pass in whatever was necessary as a parameter to the function. In a small student program, though, you could also declare the important variables globally (meaning you declare them outside of any function), and then they will be available to all functions of your program.

Also, if your program is small, posting it (with [code] [ /code] tags) would help people give more specific answers.

Ahhh, look at your function call to get_input. You have three variables declared in main() - product, quantity, and price - that you pass to get_input.

The function get_input gets a copy of these values to use. So when it does its work by filling the data with user input, it does the work on the copies. The original variables in the main() method don't get changed.

To fix this, I would suggest passing a reference to these variables to your method. All you have to do is change your declaration and definition of get_input:

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.