I have tried to solve this using different loops and loops with if statements. I keep getting compile errors no matter what I do. I finally tried a do-while loop and the code below finally compiles but it seems to be a infinate loop. Can someone please point me in the correct direction. I have searched for answers, and worked on this for two days now. I have completed all the other exercises for this chapter but this one. For some reason I just can't get my head around it.
Here is the problem:
Write a menu program that lets the user select from a list of options, and if the input is not one of the options, reprint the list
This is incorrect: while ( option != "1" || "2" || "3" || "4" )
What you're saying right now is "keep looping as long as any one (or more) of the following are true:
-- option != "1"
-- "2" evaluates to non-zero (always true)
-- "3" evaluates to non-zero (always true), or
-- "4" evaluates to non-zero (always true)."
Hence the infinite loop.
So it should be while (option != "1" && option != "2" && option != "3" && option != "4").
In reality, you don't need a string for this -- you can just make option an int, in which case you can just do while (option < 1 || option > 4).