table turmoil

This is a discussion on table turmoil within the C++ Programming forums, part of the General Programming Boards category; Actually, I was wondering if soemone would review my code below. Is there a better way to output the information ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    4

    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 pre-assigned 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;

    }

  2. #2
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 06:06 PM
  2. progarm doesnt compile
    By kashifk in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2003, 06:54 PM
  3. extra word printing
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 05:03 PM
  4. inputting words from a file
    By kashifk in forum C++ Programming
    Replies: 5
    Last Post: 10-24-2003, 08:18 AM
  5. help with operator <
    By kashifk in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2003, 04:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21