Need help with simple code. Very new to C++
OK, I am very new to C++ so if anything is incorrect or there is an easier way or whatever, please let me know.
Here is some code I wrote just to mess around and try to start a program. I was trying to create a simple menu.
Code:
#include <iostream>
using namespace std;
int main()
{
int Selection;
cout << "Welcome to BlackJack! Choose an option below to continue:\n";
cout << "\n";
cout << "1)New Game\n";
cout << "2)Restore Game\n";
cout << "3)Exit\n";
cout << "\n";
cout << "Selection: ";
cin >> Selection;
switch (Selection)
{
case 1:
system("cls");
break;
case 2:
system("cls");
break;
case 3:
system("cls");
break;
default:
system("cls");
cout << "Invalid Selection";
break;
}
system("pause");
return 0;
}
As you can see, my 3 cases don't do anything besides clear the screen. I was going to make each case go to another submenu after clearing the screen but I haven't gotten to that yet. What I was trying to figure out is... on my default case, I want to make it return to the beginning and ask for the selection again after displaying it was an Invalid Selection. how can I do this?
Also, I tried making line 13 say:
Code:
while(cout << "Selection: ");
But that just made the program keep displaying Selection over and over again in an infinite loop? can someone explain why this is please?