Im currently attempting to create a text based game but early on im encountering a problem where if you were to type 3 instead of 1 or 2 it would end the program instead of looping back to ask for 1 or 2 again. i'm also having trouble implementing a save and load feature as well if anyone can to help me with this.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int option;
int Title;
cout << "Hemlok\n";
cout << "MENU\n\n";
cout << "1 To start new game\n";
cout << "2 To load your game\n";
cout << "Insert option now: ";
cin >> option;
if(option==1)
{
cout << "Welcome to Hemlok, the mighty kingdom of Orcs and Humans.\n";
cout << "Pick your race: ";
cout << "1 - Human\n";
cout << "2 - Orc\n";
int playerRace;
cin >> playerRace;
switch (playerRace)
{
case 1:
cout << "You picked the Human race.\n";
{
{
cout << "Enter your heros name:";
string name;
cin >>name;
cout << "Your journey begins, " << name <<".\n";
cout << "///////////////////////CHAPTER 1 : OH MY CAININES/////////////////////////\n";
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int option;
int Title;
do
{
cout << "Hemlok\n";
cout << "MENU\n\n";
cout << "1 To start new game\n";
cout << "2 To load your game\n";
cout << "Insert option now: ";
cin >> option;
if(option==1)
{
//Does something...
}
if(option==2)
{
//May do something
}
//You need to implement an exit code!
}while(option<=2 || option>=1);
return 0;
}
Make sure to implement an exit procedure, example:
1 2 3 4
if(option==3)
{
break;//Break out of the current loop!
}
Or:
1 2 3 4 5
if(option==3)
{
//Prompt any info, because loop will certainly break!
}
}while(option<=2 || option>=1 && option!=3);
Tip: Handing you the fish won't help you, the below is long but will teach you the flow control operations:
http://www.cplusplus.com/doc/tutorial/control/
Use your browsers find feature (usually ctrl-f) and seek "The do-while loop".