I'm really really new to C++ and i'm just trying to make a start of a text based game. I have 2 while loops and i'm wondering how to get back to the start of the first loop (please enter a name for your character) when the player types 'n' as name_confirm. I see where the problem is but i'm not sure how to make it work.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string char_name;
char name_confirm = 'n';
bool name_correct = false;
cout << "Welcome to <Insert Game Name Here>" << endl;
while(name_correct == false)
{
cout << "Please enter a name for your character: ";
cin >> char_name;
while(name_confirm != 'y')
{
cout << "You have chosen: " << char_name << ". Is this correct? (y/n)" << endl;
cin >> name_confirm;
if(name_confirm == 'y')
{
name_correct = true;
}
else if(name_confirm == 'n')
{
name_correct = false;
}
else
{
cout << "Please choose either 'y' if the name is correct or 'n' if it is not." << endl;
name_correct = false;
}
}
}
return 0;
}