The program wants me to build a menu that incorporates call functions. There are three selections in the menu (Ohm's Law, Number Guessing Game, and the option to End Program). I've declared and defined my two functions "game" and "ohmslaw" before my source code as cplusplus.com has instructed me to do from the reference tab in the section titled (Functions I).
I'm having trouble defining the function "game". I'm receiving three errors in lines 90, 144 and 191 . I've tried to define the function "game" using a switch, like I defined the function "ohmslaw" to be. This is not compiling I believe I'm using the wrong control structure for the function "game".
I've successfully compiled the function "ohmslaw" so i know it works. Therefore, my problem is in the function "game". I got this code for the guessing game out of an example in my book. It doesn't use it as a call function though. So i'm completely lost how to define the function "game" so it runs smoothly and exits smoothly.
I've tired to be as technical and organized to make troubleshooting more efficient. I apologize in advance if it's not to your standard. I'm a student and this is one of the labs for this week. I'm just having a hard time and here it's 4:19AM and i'm still at it.
The code is constructed in Xcode and the environment is OS X if this is important to know. Thank you for your time and any advice.
You are missing the while in the do-while loop in game.
When you have defined and initialized a variable in one statement you are not allowed to jump (by using a switch-case or goto) over it to skip that statement to a place where the variable is still in scope. If it was possible, doing so would allow you to access variables that has not been initialized even though they have constructors that would normally do the initialization.
So when defining variables inside a switch the trick is to limit the scope of the variables by using a pair of { }, so that the scope doesn't cross any case labels.
Don't call srand every time you call rand. It will make it less random. Instead call srand once and only once in your program (at the beginning of main is a good place).