Thread: Needing help with C++ programming assignment.

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    7

    Needing help with C++ programming assignment.

    Not looking for you to tell me how to redo the whole thing, just need help pointing out why it dependency keeps dropping.
    ( Circular PmtCalc.o <- Pmtcalc.cpp dependency dropped. )
    It isnt a homework thing its just a in class assignment that has been bugging me because I could not get the result needed.
    Do note, I just started my class a week ago, so if the code looks bad do not down it.
    Code:
    //Monthly Payment on New car
    
    
    #include <cstdlib>
    #include <iostream>
    #include <math.h>
    
    
    using namespace std;
    
    
    int main()
    {
        int num1;
        int num2;
        int num3;
        int num4;
    
    
        float math;
        math = pow(1+119,60);
    
    
    //Down Payment
        num1 = 2200;
    //Car Price
        num2 = 22000;
    //Monthly interest rate
        num3 = 119;
    //Number of Months
        num4 = 60;
        cout<< "Monthly carpayment= " << num3 * (num2 - num1) * ( math/ math -1);
    
    
        system("PAUSE");
        return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That message you get means you wrote your Makefile incorrectly, not your code.

  3. #3
    Registered User
    Join Date
    Jan 2014
    Posts
    7
    I was wondering why it was doing that. Now I feel stupid. lol

  4. #4
    Registered User
    Join Date
    Jan 2014
    Posts
    7
    Any help to why my calculation keeps coming up wrong?

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I didn't run the program, but probably because you're not taking order of operating into account.

    (math / math - 1)

    is equivalent to

    ( (math/math) - 1)

    is equivalent to

    (1 - 1)
    Last edited by Matticus; 01-17-2014 at 12:00 PM. Reason: missed a float declaration

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Were you supposed to be paying 11900% interest? If not, maybe you shouldn't use that number.

  7. #7
    Registered User
    Join Date
    Jan 2014
    Posts
    7
    I was taking it into account, just not really grasped the concept of making it go into programming. The assignment is trying to figure out monthly car payment value, with the car being 22000, down payment 2200, and 5 year at 6.5% apr. The equation he put out to us just threw me off a good bit. I know the outcome outside of the program, just keep messing it up when trying to put it into program.

  8. #8
    Registered User
    Join Date
    Jan 2014
    Posts
    7
    Oh I changed the number back to original, was throwing out numbers for the first part trying to see why it kept coming out 0. But the previous guy said it was from my PEMDAS problem within the code.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    So, what is your current code, and how does it not work? Or if it works, you could still post it for suggestions on improvement, or just for checking that it really works.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Jan 2014
    Posts
    7
    Code is working at the moment, I am having problems trying to do calculations within it. I am trying to come out with the monthly payment of 430.46. I'm confused on how my calculations are not going through right. it always comes back either 0, or 1#inf. Matticus said its my order of operations mess up, but I am clueless on how to put it in to run correctly.
    Code:
    //Monthly Payment on New car
    
    
    #include <cstdlib>
    #include <iostream>
    #include <math.h>
    
    
    using namespace std;
    
    
    int main()
    {
        int num1;
        int num2;
        double num3;
        int num4;
        int num5;
        double num6;
        
        float math;
        math = pow(1+0.00541666666,60);
        float math2;
        math2 = pow(0.00541666666,60);
    //Down Payment
        num1 = 2200;
    //Car Price
        num2 = 22000;
    //Monthly interest rate
        num3 = 0.00541666666;
    //Number of Months all together
        num4 = 60;
    // Year
        num5 = 12;
    // APR
        num6 = 6.5;
        cout << "Prices on my new car!" << endl;
        cout << "Purchase Price= "<< num2 << endl;
        cout << "Yearly APR=%"<< num6 << endl;
        cout << "Monthly Interest= "<< num6 / num5 << endl;
        cout << "Interest* (purchase-Downpayment)= "<< num3 * (num2 - num1);
        system("PAUSE");
        return 0;
    }

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The formula goes something like

    PMT = (price)(I/12)/(1-(1+I/12)^-60)

    Notice you have to do the pow, and then take 1 minus that. Notice also the exponent is negative.

  12. #12
    Registered User
    Join Date
    Jan 2014
    Posts
    7
    With what you said it came out with a actual price.
    cout<< "Monthly carpayment= "<< num3 * (num2 - num1) * ( math/ math -1);
    That is the way I attempted to run it. The initial formula on our assignment read like this I(price-downpayment)[(1+I)^60/(1+I)^60-1]
    I= Monthly Interest rate

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by killeramor View Post
    With what you said it came out with a actual price.
    cout<< "Monthly carpayment= "<< num3 * (num2 - num1) * ( math/ math -1);
    That is the way I attempted to run it. The initial formula on our assignment read like this I(price-downpayment)[(1+I)^60/(1+I)^60-1]
    I= Monthly Interest rate
    That's algebraically equivalent to the one I gave (relabel I as monthly instead of yearly, then multiply top and bottom by (1+I)^60). Note you still have to put the entire denominator (math-1) in parentheses like so (math/(math-1)).

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Perhaps better variable names like 'principle', 'interest', 'repayment' and 'term' would make for much more readable code than num[1-6]

    It makes the code that much easier to check, rather than having to keep reminding yourself, "oh, what's num4 again, oh damn, I forgot my question".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob needing help with large C assignment
    By Dan2mc in forum C Programming
    Replies: 5
    Last Post: 08-06-2013, 09:28 PM
  2. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  3. Help with Programming Assignment
    By JHaney in forum C++ Programming
    Replies: 18
    Last Post: 11-08-2005, 03:45 AM
  4. programming assignment help
    By the_winky_files in forum C Programming
    Replies: 3
    Last Post: 09-23-2005, 11:59 AM
  5. Needing a really cool programming idea...
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-26-2005, 08:12 AM

Tags for this Thread