vendredi 4 septembre 2020

Nested If If statement is skipping user's chance to input data for the second question

Updated to describe the issue more accurately

I am trying to use a nested if if statement for learning purposes (tutorial following along with). I am aware the logical && operator would be ideal for this situation. Anyways...

The nested If If statement is skipping the user's chance to input data for the second question when the first guess equals the first answer. When the first guess is incorrect, everything runs as intended (both questions and user input request execute)

I could be mistaken but I feel everything is on par with the tutorial yet I keep encountering the issue I mentioned. Anyone got an answer? :)

Thanks :)



#include <iostream>
#include <string>

int main ()
{
std:: string variable_one_guess;
std:: string variable_two_guess;
std:: string variable_one_answer = "The answer for one";
std:: string variable_two_answer = "The answer for two";

std:: cout << "Guess the variable one value\n";
std:: cin >> variable_one_guess;
std:: cout << "Guess the variable two value\n";
std:: cin >> variable_two_guess;


if (variable_one_guess == variable_one_answer) // I am aware I can just combine both if statements using the logical
                                      //  && operator but I need this to work for learning purposes

{

    if(variable_two_guess == variable_two_answer)

    {std:: cout << "Correct!\n";}

}

}

Aucun commentaire:

Enregistrer un commentaire