
table turmoil
Actually, I was wondering if soemone would review my code below. Is there a better way to output the information and make it look nicer? Did I follow the algorithm step by step? Thanks in advance for your input.
Problem:
The outstanding balance on Rhona's car is $5,000.00. Each month, she is required
to make a payment of $300.00, which includes both interest and principal repayment
of her car loan. The monthly interest is calculated as 0.09/12 of the outstanding
balance of the loan. After the interest is deducted, the remaining part of the
payment is used to pay off the loan. Write a C++ program that produces a table
indicating the beginning monthly balance, the interest payment, the prinicpal payment,
and the remaining loan balance after each payment is made.
Note: Follow this preassigned algorithm:
Output Header
Initialize Balance
Initialize payment
Loop
Calculate Interest Payment ( = 0.09/12 * Balance)
If Interest Payment + Balance < Payment
Calculate Principal ( = Balance)
Else
Calculate Principle ( = Payment  Interest Payment)
Calculate Ending Balance ( = Balance  Principle)
Output Data
Calculate New Balance ( = Ending Balance)
While Balance > 0
Code:
#include <iostream.h>
#include <iomanip.h>
int main()
{
float balance = 5000.0;
float rate = 0.09/12;
float payment = 159;
float interest, principal;
cout << " Beginning Interest Principal Ending Loan\n";
cout << " Balance Payment Payment Balance \n";
cout << " \n";
cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);
while (balance < 0.05)
{cout << setw(11) << balance;
interest = rate * balance;
prinicpal = payment  interest;
balance = balance  principal;
cout << setw(10) << interest
<< setw(10) << principal
<< setw(10) << balance << endl;
}
return 0;
}

Firstly  to make the code look nicer on THIS forum, use CODE tags. :)
Second, I have only read the spec briefly, but I am confused by the conditional in the while loop. You are executing the loop while the balance is less than 0.05, but the algorithm asks you to execute while the balance is greater than 0.
The algorithm also talks of a conditional statement, but I don't see that in the code. I could be misreading this.. I am REALLY tired right now.