#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
float annualIntRate, principle, monthlyPayment, monthlyIntRate, totalAmt, intPaid;
int yearsBorrowed, numPayments;
cout << "This program computes information associated with a loan" << endl;
cout << "Please input the Annual Interest Rate:" << endl;
cin >> annualIntRate;
cout << "Pleast input the number of years for which you have to pay back the loan:" << endl;
cin >> yearsBorrowed;
cout << "Please enter the amount that has been borrowed:" << endl;
cin >> principle;
monthlyIntRate = annualIntRate / 12;
numPayments = yearsBorrowed * 12;
monthlyPayment = principle * (monthlyIntRate/100.0 * pow(1 + monthlyIntRate/100.0, numPayments))/(pow(1 + monthlyIntRate/100.0, numPayments) - 1);
totalAmt = monthlyPayment * numPayments;
intPaid = totalAmt - principle;
cout << setprecision(2) << fixed;
cout << "Loan amount:" << setw(10) << "$" << principle << endl;
cout << "Monthly Interest Rate:" << setw(10) << monthlyIntRate << "%" << endl;
cout << "Number of Payments:" << setw(10) << numPayments << endl;
cout << "Monthly Payment:" << setw(10) << "$" << monthlyPayment << endl;
cout << "Total Amount Paid:" << setw(10) << "$" <<totalAmt << endl;
cout << "Interest Paid:" << setw(10) << "$" << intPaid << endl;
return 0;
}
Why is my code not aligned using the setw manipulator and instead it is just created a space of 10 spaces?