At the near end of the code you'll see how I tried to capture the capitol Q but it didn't work. Any advice?
#include <iostream>
#include <stdexcept>
using namespace std;
//global constants
//currently none
//function prototypes
//variables
char mainoption; //declare main menu option variable
int main()
{
// The MAIN MENU, which is the start screen for the game.
cout <<"MAIN MENU:\n\n";
cout <<"1- Create a Character\n";
cout <<"2- Load an Existing Character\n"; // Most common selected
cout <<"3- Delete a Character\n";
cout <<"4- View Existing Character List\n"; // For those poor forgetful folk like me
cout <<"Q- Quit Game (AT ANY TIME WITH OUT SAVING)\n\n";
//main menu loop
do
{
cout <<"Please select an option above: ";
cin >> mainoption;
switch (mainoption)
{
case '1':
cout <<"create character\n"; //replace with call to newplayer
break;
case '2':
cout <<"load character\n"; //replace with call to loadplayer in town
break;
case '3':
cout <<"delete character\n"; //replace with call to deleteplayer
break;
case '4':
cout <<"view character list\n"; //replace with call to charlist
break;
case 'q': //is there a way to account for capitol "Q" also?
//try to quit
continue;
default:
cerr <<"Selection " << mainoption << " is not a valid option.\n";
}
}
while (mainoption != 'q' && 'Q');
Sorry I was unaware of the "code tag" and will look for it next time. =+S
And thank you for the help! The latter version was what I was trying to express, but I was having a massive mind block on the subject. Also would I be able to safely remove the &&'Q' from the while (mainoption...) ?
I'm unfamiliar with "continue" and must assume that the reason my program functioned correctly in the do while is because of my capture error? I will test again with the prescribed adjustments, but I'd like to know more about this "continue" you speak of hentaiw. My thanks to all of you who posted advice here to include Peter87. =+}
#include <iostream>
#include <stdexcept>
usingnamespace std;
//global constants
//currently none
//function prototypes
//variables
char mainoption; //declare main menu option variable
int main()
{
// The MAIN MENU, which is the start screen for the game.
cout <<"MAIN MENU:\n\n";
cout <<"1- Create a Character\n";
cout <<"2- Load an Existing Character\n"; // Most common selected
cout <<"3- Delete a Character\n";
cout <<"4- View Existing Character List\n"; // For those poor forgetful folk like me
cout <<"Q- Quit Game (AT ANY TIME WITH OUT SAVING)\n\n";
//main menu loop
do
{
cout <<"Please select an option above: ";
cin >> mainoption;
if (mainoption == 'Q')
{
mainoption = 'q';
}
switch (mainoption)
{
case'1':
cout <<"create character\n"; //replace with call to newplayer
break;
case'2':
cout <<"load character\n"; //replace with call to loadplayer in town
break;
case'3':
cout <<"delete character\n"; //replace with call to deleteplayer
break;
case'4':
cout <<"view character list\n"; //replace with call to charlist
break;
case'q': //is there a way to account for capitol "Q" also?
//try to quit
break;
default:
cerr <<"Selection " << mainoption << " is not a valid option.\n";
}
}
while (mainoption != 'q');
return 0;
}
No I'm sorry,because you don't have a code tag so I had a mistake looking at your code...It works fine,I rewrote
My thanks again, and I will try to utilize the code tag. I apologize for the standard posting violation, I hope to learn more and help others here also. =+}