brentf
brentf

Reputation: 411

OR (||) operator not working correctly in C++

I cannot figure out why my code isn't running correctly - I am simply assigning a bunch of values from a lookup table, then running a check to make sure the values are all equal to zero. For some reason, the "check" I am running keeps failing (and assigning default values), even though the underlying numbers do not justify it - can someone explain to me why my "if / or" statement isn't working below? I have verified that all of the values I am assigning above are valid at the time of assignment...

    PF[i].pMktRefNoi = MD[mProp[i].m_NoiVectorNumber-1].Values[mProp[i].m_StartfColNum-1];
        cout << PF[i].pMktRefNoi << endl;
    PF[i].pMktRefVal = MD[mProp[i].m_ValVectorNumber-1].Values[mProp[i].m_StartvColNum-1];
        cout << PF[i].pMktRefVal << endl;
    PF[i].pMktRefRent = MD[mProp[i].m_RntVectorNumber-1].Values[mProp[i].m_StartfColNum-1];
        cout << PF[i].pMktRefRent << endl;
    PF[i].pMktRefOcc = MD[mProp[i].m_OccVectorNumber-1].Values[mProp[i].m_StartfColNum-1];
        cout << PF[i].pMktRefOcc << endl;

    // Error check the starting values we just assigned
    if (PF[i].pMktRefNoi <= 0 || PF[i].pMktRefVal <= 0 || PF[i].pMktRefRent <= 0 || PF[i].pMktRefOcc <= 0); {
    PF[i].Result = "Error - Invalid Starting Vector Value";
    PF[i].pMktRefNoi = 100;
    PF[i].pMktRefVal = 100;
    PF[i].pMktRefRent = 100;
    PF[i].pMktRefOcc = 100;
    }

So in the code above, each of the "cout" statements verifies to me on output that all of the values were correctly assigned and are greater than zero. BUT, everything is still getting re-assigned to 100 after the if statement - can anyone explain what is wrong with my code?

Upvotes: 2

Views: 205

Answers (1)

user229044
user229044

Reputation: 239230

You've an extra semi-colon after your if.

This...

if (...); {

}

... needs to be this:

if (...) {

}

In the first case, the code attached to the if is the single empty statement, ;. Then the block of code within the {} is executed regardless of the outcome of the if.

Upvotes: 13

Related Questions