[Solved] expected expression error in nested if statement c++


Edit: I was wrong, here’s the error:

    else
    {
    if (userin_1 == 10 && userin_2 == 10 && userin_3 == 10)
    score = userin_1 + userin_2 + userin_3;
    cout << "Wowow 3 strikes! Your score is " << score << endl;
    }
        else
        {
        if (userin_1 == 10 && userin_2 == 10)
        score = userin_1 + userin_2 + userin_3;
        cout << "Two strikes! Your score is " << score << endl;
        }

The second else has no associated if before it. Move the if‘s into the corresponding else clauses.

    else if (userin_1 == 10 && userin_2 == 10 && userin_3 == 10) {
        score = userin_1 + userin_2 + userin_3;
        cout << "Wowow 3 strikes! Your score is " << score << endl;
    } else if (userin_1 == 10 && userin_2 == 10) {
        score = userin_1 + userin_2 + userin_3;
        cout << "Two strikes! Your score is " << score << endl;
    }

However, the more serious problem here is the way you approach the task. There are way too many nested if statements for this task. You repeat yourself a few times on the conditions, whereas the proper way would be to only check the condition once and then branch off.

Also, statements like

if (userin_1 <= 10 && userin_2 <=10 && userin_3 <=10)
    userin_1 = userin_1;

make no sense, you should instead check for the opposite and skip the else clause altogether.

You should also use proper indentation, as it greatly helps to improve code readability and helps avoid errors like these.

5

solved expected expression error in nested if statement c++