c - If Else in a While Loop -


i having trouble code. when run it, prints out 2 lines in while statement. i'm trying run if statement until mortgageleft

can see mistake i'm making? idk if helps, if delete else statement, program runs fine

#include <stdio.h> #include <stdlib.h>  int main(){     float mortgageleft, interestrate, monthlypayment, monintrate, amountowed;     int month=0;      printf("what value left on mortgage?\n");     scanf("%f", &mortgageleft);      printf("what annual interest rate of loan, in percent?\n");     scanf("%f", &interestrate);      printf("what monthly payment?\n");     scanf("%f", &monthlypayment);      monintrate= (interestrate/12)/100;      printf("month\t\t payment\t amount owed\n");      while (mortgageleft>0)     {         if(mortgageleft>monthlypayment)         {             mortgageleft=(mortgageleft*monintrate)+mortgageleft;             mortgageleft=mortgageleft-monthlypayment;                 month++;             printf("%d\t\t %.2f\t\t %.2f\n", month, monthlypayment, mortgageleft);         }         else             mortgageleft=(mortgageleft*monintrate)+mortgageleft;         month++;         printf("%d\t\t %.2f\t 0", month, mortgageleft);         mortgageleft=0;     }     return 0; } 

it appears missing brackets

while (mortgageleft>0)     {         if(mortgageleft>monthlypayment)         {         mortgageleft=(mortgageleft*monintrate)+mortgageleft;         mortgageleft=mortgageleft-monthlypayment;             month++;         printf("%d\t\t %.2f\t\t %.2f\n", month, monthlypayment, mortgageleft);         }         else         {         mortgageleft=(mortgageleft*monintrate)+mortgageleft;         month++;         printf("%d\t\t %.2f\t 0", month, mortgageleft);         mortgageleft=0;         }    } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -