forresto
forresto

Reputation: 9

if conditions are being ignored

currently,the conditions of my if loop are not being respected. no matter what I enter for x, the statements inside the for loop still run. The idea here is that the user can enter data, and if they want to change the data before the next step, they can. At the end of the while loop, they should have the option to jump back to the start, or exit the while loop. I initially attempted to do a while loop inside a while loop, but that returned no result at all.

int _tmain(int argc, _TCHAR* argv[]) {
    dataSet myData;
    int a, b, c, d, x, y;
    cout << "2 to start, 1 to fail." << endl;
    cin >> y >> x;
    while (y == 2) {
        if (x == 1);
        {
            cout << "please enter 4 numbers: " << endl;
            cin >> a >> b >> c >> d;
            int start[4] = { a, b, c, d };
            myData.addElements(start);
            x = myData.moveForward;
        }
        myData.beginProcess();
        y = myData.moveForward;
        x = myData.moveForward;
    }

    system("pause");
    return 0;
}

Upvotes: 0

Views: 648

Answers (3)

melak47
melak47

Reputation: 4850

Your if statement does nothing, because:

if (x == 1);
           ^~~~ empty statement!

I suggest your raise your warning level to at least /W3, then the compiler would have warned you:

warning C4390: ';' : empty controlled statement found; is this the intent?

Upvotes: 2

SJuan76
SJuan76

Reputation: 24780

if (x == 1);

if (x == 1) will execute the next instruction. Which is just ;, the "void" instruction.

After that, the if block has ended and continues executin the next of the code (the nested block you think was to be executed only if x == 1)

Upvotes: 0

user3147395
user3147395

Reputation: 541

There should be no ; after the if statement

Upvotes: 0

Related Questions