Thread: Problems

  1. #1
    Registered User ProgrammingDlux's Avatar
    Join Date
    Jan 2002
    Posts
    86

    Problems

    Hey guys, if anyone can help I'd greatly appreciate it. I have this homework problem that doesn't seem to wanna work with me.
    "you have bought a car, taking out a loan with annual interest rate of 9%. You will make 36 monthly payments of $165.25 each. You want to keep track of the remaining balance you owe after each monthly payment. The formula for the remaining balance is:

    Bal k= pmt[1-(1+i)^(k-n)]/i

    Bal k = balance remaining after kth payment
    k= payment number (1,2,3...)
    pmt= amount of monthly payment
    i= interest rate per month (annual rate /12)
    n= total number of payments to be made.

    If you're still reading this ..here is the source code I've gotten so far... Please Help

    #include<iomanip.h>
    #include<math.h>

    main()
    { _asm finit;
    int K, N;
    float Pmt=165.25, I=.09, Bal;

    for (N=1;N<=36;N++){
    cout<<"\nPayment Number: "<<N<<endl;

    Bal = Pmt* (1- pow((1+(I/12)),N-K))/(I/12);

    cout.setf(ios::floatfield, ios::showpoint);
    cout.setf(ios::fixed) ;
    cout<<setprecision(2) ;

    cout<<"Monthly Payment is: $" <<Pmt<<endl; cout<<"Monthly Interest Rate is: " <<I<<endl ;
    cout<<"Total Number of Payments is: "<<N<<endl ;
    cout<<"Balance is : $" <<Bal<<endl;

    }//for loop

    return 0;
    }//main

  2. #2
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Here, I fixed up your code.

    Mainly, you had the variables N and K doing each other's job. So I just switched those and did some other housekeeping. I believe that this is what you wanted:
    Code:
    #include<iomanip.h> 
    #include<math.h> 
    
    main() 
    { 
       _asm finit;
    	
       int K,  N = 36; 
       double Pmt = 165.25, I=0.09, Bal; 
    
       for (K = 1; K <= 36; K++)
       { 
        cout << endl <<"Payment Number: "<< K << endl; 
    
        Bal = Pmt * ( 1 - pow((1 + I/12),(K - N)) ) / (I/12);  //Bal k= pmt[1-(1+i)^(k-n)]/i  
    
         cout.setf(ios::floatfield, ios::showpoint); 
         cout.setf(ios::fixed) ; 
    
    		
        cout << setprecision(2)
             << "Monthly Payment is: $" << Pmt <<endl
             << "Monthly Interest Rate is: " << I/12 <<endl 
             << "Total Number of Payments is: "<< N <<endl  
             << "Balance is: $" << Bal <<endl; 
    
       }
    
    return 0; 
    }
    Good luck

  3. #3
    Registered User ProgrammingDlux's Avatar
    Join Date
    Jan 2002
    Posts
    86

    Thanks

    Hey thanks a lot bro..I appreciate it big time!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM