3
Hi guys I’m trying to make a controlled loop for my program, so far it’s running normal only in the first round, in the second repeat it jumps the first pass of the go and starts in the second position if anyone wants to see my code:
void Intro_Game();
void Login_Entrace();
bool Ask_PlayAgain();
string User_Login(string);
constexpr int WORLD_LENGHT = 5;
int main()
{
bool PlayAgain_Count = false;
do
{
system("cls");
Intro_Game();
Login_Entrace();
PlayAgain_Count = Ask_PlayAgain();
} while (PlayAgain_Count);
return 0;
}
void Intro_Game()//Intro Game
{
cout << "Welcome to Bulls & Cow\n";
cout << "Can you guess the " << WORLD_LENGHT << " isogram I'm think of?\n\n";
}
//entrace of data process fase
void Login_Entrace()
{
string x[5];
int j = 1;
//begin fase
for (int i = 0; i < WORLD_LENGHT; i++)
{
cout << "Enter with Guess " << j << ": ";
x[i] = User_Login(x[i]);
system("cls");
j++;
}
j = 0;
for (int i = 0; i < WORLD_LENGHT; i++)
{
++j;
cout << "Guess " << j << " name is: " << x[i] << "\n\n";
}//end fase
}
bool Ask_PlayAgain()
{
string resp;
cout << "Do wanna play again?\n";
cin >> resp;
if (resp[0] == 'Y' || resp[0] == 'y')
return true;
if (resp[0] == 'N' || resp[0] == 'n')
{
system("cls");
cout << "You say no. =(\n";
return false;
}
if(resp[0] != 'N' || resp[0] != 'n' && resp[0] != 'Y' || resp[0] != 'y')
{
system("cls");
cout << "Wrong awnser please try again\n";
return Ask_PlayAgain();
}
}
//Read user login name
string User_Login(string Guess)
{
getline(cin, Guess);
return Guess;
}
Updating
Folks I will post this photo I hope you exemplify my question.
Update with response (explanation of Gomiero in the response posted below)
Let me get this straight...at the first execution he spins the two is straight, only on Monday he jumps the first and executes only the second? If not, try to clarify.
– Dunga Cardoso
Almost ... so the first is the first time he reads the 5 Guess right and prints straight, then calls the askplay_again... if I answer Yes he starts the do again but he already starts asking to read the second Guess... in case he jumps up to the intro_game and already asks the Guess 2
– Leonardo V. De Gasperin
I hope it wasn’t too complex
– Leonardo V. De Gasperin
If the console output is not too large, I think it will help clarify the problem. Add it to your question and show at what instant the program started 'wrong''...
– Berriel
In case the variable J is not passing the correct value.... that’s it?
– Dunga Cardoso
I put a photo to improve the explanation @Dungacardoso
– Leonardo V. De Gasperin
I understand now. how strange, it increases the variables.. but the variable i and J of the second is not incremented.
– Dunga Cardoso
then I’ve read and read again and nothing I could think of to do otherwise because for this kind of thing it doesn’t need much but if anyone has any idea of what is happening, I don’t know a better place to ask
– Leonardo V. De Gasperin
I do not work with this language...more have tried to take out that Count++, that if it is a variable I have not seen statement, or then try to reset the variables after it instead of before.
– Dunga Cardoso
Then every time q enters the login function it sets j=0 and when it enters the for it arrow i=0 in both for
– Leonardo V. De Gasperin
Let’s go continue this discussion in chat.
– Dunga Cardoso