Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Emergency

Emergency

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Binary0110
    wrote on last edited by
    #1

    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

    P N 2 Replies Last reply
    0
    • B Binary0110

      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

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      Binary0110 wrote:

      Can someone tell me why I can't get my output lined up.

      what do you mean by "lined up" output?


      -prakash

      1 Reply Last reply
      0
      • B Binary0110

        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

        N Offline
        N Offline
        normanS
        wrote on last edited by
        #3

        As 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 using cout(), but that is just because I am happier with C-style printf() and its parameters than the weird new-wave C++ approach (using cout() and setw() etc.)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups