Good day everyone, I'm new to C++ programming and was following the tutorials and came across a doozy in the switch ~ case tutorial. It said a loop function could be added to make the program wait for valid input, but with this code it just finishes the program no matter what the user inputs.
Is the loop code in the wrong place, or is the default part of the switch ~ case wrong?Code:#include <iostream> using namespace std; int main() { int input; cout<<"1. Play game\n"; cout<<"2. Load game\n"; cout<<"3. Multiplayer\n"; cout<<"4. Exit\n"; cout<<"Selection: "; cin>> input; do { // start loop switch ( input ) { //start switch case 1: cout<<"Playing game...\n"; break; case 2: cout<<"Loading game...\n"; break; case 3: cout<<"Loading multiplayer server...\n"; break; case 4: cout<<"Thanks for playing.\n"; break; default: input = 0; // ==, !=, } // end switch } while ( input = 0); //end loop, ==, !=, cin.get(); // a pause function to stop window from closing fast cin.get(); }
My goal is to become a fairly decent programmer in the months (years, decades!) to come, and I feel pretty dumb not being able to figure this out.



LinkBack URL
About LinkBacks


