This is the section that wont compile and i cant figure out why.It gives me the error expected primary-expression before "else" and expected ';' before "else" if anyone can help me id appreciate it!
if (currentBalance >= minimumBalance)
newBalance = currentBalance * CHECKING_INT_RATE_REG;
This is the pseusdocode my teacher gave us to use for it...
If savings account (allow for upper and lower case data being entered)
If balance greater or equal to minimum balance
compute new balance using the interest rate
else
compute new balance deducting service charge
output the new balance
else
if checking account (allow for upper and lower case data being entered)
If balance greater or equal to minimum balance
if balance is less than or equal than (minimum balance +
checking high balance)
compute new balance using the interest rate
else
compute new balance using the interest rate over 5000
else
compute new balance deducting service charge
output the new balance
else
output a message for invalid account type entered
First of all, every else has to be paired with a corresponding if, and there can only be one else per if. You really need to indent that pseudocode so it makes more sense. Where ever the indentions are, is where your brackets {} should go.
If savings account (allow for upper and lower case data being entered)
If balance greater or equal to minimum balance
compute new balance using the interest rate
else
compute new balance deducting service charge
output the new balance
else if checking account (allow for upper and lower case data being entered)
If balance greater or equal to minimum balance
if balance is less than or equal than (minimum balance + checking high balance)
compute new balance using the interest rate
else
compute new balance using the interest rate over 5000
else
compute new balance deducting service charge
output the new balance
else
output a message for invalid account type entered
Any if statement or else statement that has more than one semicolon needs curly brackets around it. So...
1 2 3 4 5 6 7 8 9 10
if(x >10)
cout << "hi" << endl;
cout << "there" << endl;
//this ALWAYS couts "there" because that statement isn't part of the if statement. so if x>10 it couts "hi there", if x <=10 it couts "there"
if(x>10)
{
cout << "hi" << endl;
cout << "there" << endl;
} //this is the correct way. Same goes with else statements.
The "invalid account type entered" will actually be your default statement in the switch cases.
if (currentBalance >= minimumBalance)
newBalance = currentBalance * CHECKING_INT_RATE_REG;
if (currentBalance <= minimumBalance)
{
//missing a statement here, need to do something here
}
else
newBalance = currentBalance * CHECKING_INT_RATE_OVER_5000;