I'm working on a program to save and load character files for a text-based RPG.
There are three slots to save to. I'm having the user enter whichever slot he wants to save to through inputting an integer. If the number is lower than 1 or higher than 3 I want the program to go back to the beginning, hence the do...while loop. However, it doesn't recognize overwriteSlot because it's local to the scope, and when I put it in the main loop the while section won't recognize the change in overwriteSlot, since it's happening locally. How can I make it so that it'll work. If the user enters 4, then have the whole thing restart. Thanks for any help!
int overwriteSlot;
do {
cout << "Which slot would you like to overwrite >> ";
cin >> overwriteSlot;
cin.ignore();
if (overwriteSlot <= 3) cout << "Save complete in slot " << overwriteSlot << "." << endl;
else cout << "There is no such slot!" << endl;
}
while (overwriteSlot < 1 && overwriteSlot > 3);