Thread: I need help with my code

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    1

    I need help with my code

    Hello guys I am a beginner in programming and I have this assignment to count mortgage. The variables given are
    Principle: 150k
    Monthly Payment: 6648.09
    How long: 3 years or 36 months

    Code:
    #include "stdafx.h"
    #include <stdio.h>
    
    
    
    
    int main()
    {
        /* declare variable */
    
    
        double principle = 150000.00;
        double interest = 0.06;
        double payMonthly = 6648.09;
        double balance;
        int years = 3;
        int months = 1;
    
    
    
    
        /* finding multipler */
        double multiplier;
        multiplier = interest / 12;
    
    
        /* calculating balance per month */
        double monthlyInterest;
        double monthlyPayment;
        double newBalance;
    
    
        monthlyInterest = principle * multiplier;
        monthlyPayment = payMonthly - monthlyInterest;
        newBalance = principle - monthlyPayment;
        do
        {
            monthlyInterest = principle * multiplier;
            monthlyPayment = payMonthly - monthlyInterest;
            newBalance = principle - monthlyPayment;
    
    
            printf("Mortgage for the %d month. \n", months);
            months = months + 1;
            printf("Principle: %.2lf Interest: %.2lf Deduction: %.2lf \n", principle, monthlyInterest, monthlyPayment);
            printf("Balance: %.2lf \n", newBalance);
        } while (months < 36);
    
    
        return 0;
    }

    When I run it, it does the loop but the numbers not updated. How do I go about fixing this?? thank you.
    I need help with my code-vvdckch-jpg

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    > newBalance = principle - monthlyPayment;
    You're never changing the remaining balance.
    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. Replies: 2
    Last Post: 09-19-2012, 01:58 PM
  2. Replies: 1
    Last Post: 03-10-2010, 11:28 AM
  3. Replies: 14
    Last Post: 04-01-2008, 02:23 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread