dimanche 8 octobre 2017

setw not working properly

Im writing a loan amortization program but when I use "setw" to set up my columns its putting "month" and "Current Balance" together and not spacing the others like I want.

I included a picture below of the output on the terminal.

cout << "Month" // sets up columns
     << setw(15) << "Current Balance"
     << setw(15) << "Interest"
     << setw(15) << "Payment"
     << setw(15) << "New Balance \n" << endl;


int month_count = 1;
while( month_count <= number_of_months) // Loops while calculating the monthly interest and new balances produced after payments.
    {
    cout << month_count
         << setw(15) << loan_amount;

    double interest = loan_amount * monthly_rate;

    cout << setw(15) << interest
         << setw(15) << payment;

    loan_amount = loan_amount + interest - payment;

    cout << setw(15) << loan_amount << endl;

    month_count++;
    }

OUTPUT

Here is how its aligning

Aucun commentaire:

Enregistrer un commentaire