Just wondering does anyone know whats wrong with this code? Trying to make a menu for my minesweeper C++ assignment but cant get it so that when you enter anything it says "Not a valid choice" I only want to be able to enter the values 1 - 4 oh and if you enter a character it messes up and just keeps printing out to the screen. -
Code: |
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <string>
#include <cmath>
#include <stdio.h>
#include <crtdbg.h>
using namespace std;
int main()
{
int default;
int choice;
bool gameOn = true;
while (gameOn != false)
{
cout << "*************************************\n";
cout << " 1 - Start the game \n";
cout << " 2 - Story \n";
cout << " 3 - Help \n";
cout << " 4 - Exit \n";
cout << " Enter your choise and press return: ";
cin >> choice;
switch(choice)
{
case 1:
cout << "game start!\n";
// rest of game code here
break;
case 2:
cout << "Story so far....\n";
// rest code here
break;
case 3:
cout << "Help\n";
// rest code here
break;
case 4: ;
cout << "End of Program \n";
gameOn = false;
break;
default;
cout << "Not a Valid Choice \n";
cout << "Choose again \n";
cin >> choice;
break;
}
}
return 0;
}
|
Thanks
George W Bush -
'...more and more of our imports are coming from overseas.'