How can i continuously subtract the money until it gets negative in C langauge?

+3 votes
asked May 28 by (150 points) 1 flag
#include <stdio.h>

int main()
{
    double mortgage;
    double payment;
    double balance;
    
    printf("Please enter a mortgage rate. \n");
    scanf ("%lf", &mortgage);
    printf("Please entert your payemnt \n");
    scanf ("%lf", &payment);
    printf("Remaining balance: %lf \n", mortgage-(mortgage*0.0285*1+payment));

    while(balance>1)
    {
        printf("Please entert your payemnt \n");
        scanf ("%lf", &payment);
        printf("Remaining balance: %lf \n", balance-(mortgage*0.0285*1+payment));
    }

    if (balance<0)
    printf("Remaining balance: %lf \n", balance-(mortgage*0.0285*1+payment));
    
    return 0;
}

1 Answer

0 votes
answered Aug 6 by (300 points)

You have not declared any value for balance variable.

That's why your program gets terminated at line 13.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...