2

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?

4

1 回答 1

13

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.

于 2013-07-08T13:00:51.597 回答