PDA

Click to See Complete Forum and Search --> : [RESOLVED] What is wrong with this statement?


Pasvorto
Jul 24th, 2007, 09:46 AM
My code:


Single PVal, TotPmts, Payment, Fmt, APR, APR2, PayType, FVal;
const int ENDPERIOD = 0;
const int BEGINPERIOD = 0;

--I will add code here later to get input data

If (APR > 1) then APR2 = APR / 100;
APR2 = APR2 / 12;


The "then" is underlined with the following message:

"; expected"

nmadd
Jul 24th, 2007, 09:53 AM
There is no "Then" in an If statement like in VB. ;)

if (APR > 1)
{
APR2 = APR / 100;
}
else
{
MessageBox.Show("APR is not greater than 1.");
}

Pasvorto
Jul 24th, 2007, 09:54 AM
I get the same error with this :

If (APR > 1)
APR2 = APR / 100;
APR2 = APR2 / 12;

Pasvorto
Jul 24th, 2007, 10:04 AM
Got it. "If" is not the same as "if". C# will take some getting used to. :-)

nmadd
Jul 24th, 2007, 10:10 AM
Got it. "If" is not the same as "if". C# will take some getting used to. :-)
That's right. :bigyello:


Also note that this:
if (1 == 2)
MessageBox.Show("What? 1 equals 2? I bet you don't see this message box.");
MessageBox.Show("Hi there. You do see me.");

is not the same as this:
if (1 == 2)
{
MessageBox.Show("What? 1 equals 2? I bet you don't see this message box.");
MessageBox.Show("Now you don't see me either.");
}

If you do not include the brackets, the if statement is only checking the first line. Personally I always use them as it is just clearer to me.
APR2 = APR2 / 12; in your code is always going to execute.

Pasvorto
Jul 24th, 2007, 10:16 AM
I want the APR2 = APR2 / 12 to always execute.

nmadd
Jul 24th, 2007, 10:21 AM
I want the APR2 = APR2 / 12 to always execute.

Ok then. It will. :bigyello:

Pasvorto
Jul 24th, 2007, 10:31 AM
Another hurdle overcome...