Emergency
-
Can someone tell me why I can't get my output lined up.
#include #include #include using namespace std; int main(void) { double l; double arate; int n; cout << " Enter the loan amount: "; cin >> l; cout << " Enter annual interest rate: "; cin >> arate; cout << "Enter total number of payments:"; cin >> n; cout<< endl<< endl; // compute monthly interest rate double mrate = (arate /12 ) / 100 ; //compute amount paid back, monthly payment, and interest paid double numerator= pow(1 + mrate , n)* mrate; double denominator= pow(1 + mrate , n) - 1; double mpayment = (numerator / denominator) * l; double apb=mpayment * 36; double ip=apb-l; int mi= arate/12; //Display Results cout << setiosflags (ios_base::internal)<<"Loan amount:"<< setw(30)<< setprecision(2)<< fixed<< "$" << l << endl; cout << "Monthly interest rate:"<< setw(30)<< mi << "%" << endl; cout << "Number of payments:"<< setw(30)<< n << endl; cout << "Monthly payment:"<< setw(30)<< "$"<< mpayment << endl; cout << "Amount paid back:" << setw(30)<< "$"<< apb << endl; cout << "Interest paid:"<< setw(30)<<"$"<< ip << endl; //system "pause"; return 0; }
BINARY -
Can someone tell me why I can't get my output lined up.
#include #include #include using namespace std; int main(void) { double l; double arate; int n; cout << " Enter the loan amount: "; cin >> l; cout << " Enter annual interest rate: "; cin >> arate; cout << "Enter total number of payments:"; cin >> n; cout<< endl<< endl; // compute monthly interest rate double mrate = (arate /12 ) / 100 ; //compute amount paid back, monthly payment, and interest paid double numerator= pow(1 + mrate , n)* mrate; double denominator= pow(1 + mrate , n) - 1; double mpayment = (numerator / denominator) * l; double apb=mpayment * 36; double ip=apb-l; int mi= arate/12; //Display Results cout << setiosflags (ios_base::internal)<<"Loan amount:"<< setw(30)<< setprecision(2)<< fixed<< "$" << l << endl; cout << "Monthly interest rate:"<< setw(30)<< mi << "%" << endl; cout << "Number of payments:"<< setw(30)<< n << endl; cout << "Monthly payment:"<< setw(30)<< "$"<< mpayment << endl; cout << "Amount paid back:" << setw(30)<< "$"<< apb << endl; cout << "Interest paid:"<< setw(30)<<"$"<< ip << endl; //system "pause"; return 0; }
BINARYBinary0110 wrote:
Can someone tell me why I can't get my output lined up.
what do you mean by "lined up" output?
-prakash
-
Can someone tell me why I can't get my output lined up.
#include #include #include using namespace std; int main(void) { double l; double arate; int n; cout << " Enter the loan amount: "; cin >> l; cout << " Enter annual interest rate: "; cin >> arate; cout << "Enter total number of payments:"; cin >> n; cout<< endl<< endl; // compute monthly interest rate double mrate = (arate /12 ) / 100 ; //compute amount paid back, monthly payment, and interest paid double numerator= pow(1 + mrate , n)* mrate; double denominator= pow(1 + mrate , n) - 1; double mpayment = (numerator / denominator) * l; double apb=mpayment * 36; double ip=apb-l; int mi= arate/12; //Display Results cout << setiosflags (ios_base::internal)<<"Loan amount:"<< setw(30)<< setprecision(2)<< fixed<< "$" << l << endl; cout << "Monthly interest rate:"<< setw(30)<< mi << "%" << endl; cout << "Number of payments:"<< setw(30)<< n << endl; cout << "Monthly payment:"<< setw(30)<< "$"<< mpayment << endl; cout << "Amount paid back:" << setw(30)<< "$"<< apb << endl; cout << "Interest paid:"<< setw(30)<<"$"<< ip << endl; //system "pause"; return 0; }
BINARYAs Mr.Prakash says, what do you mean by "can't get my output lined up"? Include a sample of the output of your program, showing the problem (AND MAYBE AN EXAMPLE OF WHAT YOU WANT.) My approach would be to use
sprintf()
function, to generate a string with the right formatting before usingcout()
, but that is just because I am happier with C-styleprintf()
and its parameters than the weird new-wave C++ approach (usingcout()
andsetw()
etc.)