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;

		if (overwriteSlot <= 3) cout << "Save complete in slot " << overwriteSlot << "." << endl;
		else cout << "There is no such slot!" << endl;
	while (overwriteSlot < 1 && overwriteSlot > 3);

overwriteSlot < 1 && overwriteSlot > 3 is always false, because no value can be less than 1 and greater than 3 at the same time. So your loop will never terminate.

I am guessing that you meant to write || rather than &&.

Ah, that's it. Yeah, I must've had something going on in my head. It works fine now, thanks!

This question has already been answered. Start a new discussion instead.