I need help getting it to be continuous. After it displays the output for the us
ID: 3818010 • Letter: I
Question
I need help getting it to be continuous. After it displays the output for the user. I want it to ask the user if he or she would like to run again,(if yes) and then make it loop back to ask the same user for another loan amount, interest and years.So the month has to start over from 1 for the second one(just like the first one. And if they choose NO, to end the program. Please help me.
I just want it to be continuous.Thank you.
I need help creating a Mortgage calculator in C programming(not C++)
My code here:
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
int main(void)
{
double principle, toprinciple, principal;
double annual_rate;
double monthly_rate;
double interest_accrued;
double payment = 1;
int month = 1;
int year, n;
char myname[40] = "Jordan";
char username[40];
//title
printf("******************************************************************************** ");
printf("*******************************MORTGAGE CALCULATOR****************************** ");
printf("******************************************************************************** ");
printf(" "); //creates a blank line
printf(" ");
printf("Welcome to my Mortgage program! My name is %s. ", myname);
printf("Please enter your name. ");
scanf_s("%s", username, 40);
printf(" Enter principle amount of the loan, %s: ",username);
scanf_s("%lf", &principle);
printf(" Enter annual interest rate,%s (ex:5%%) ",username);
scanf_s("%lf", &annual_rate);
printf(" %s, Please enter the term in years (ex. 20) and press ENTER ",username);
scanf_s("%d", &year);
printf(" ");
printf(" ");
monthly_rate = annual_rate / 1200;
payment = (principle*annual_rate / 12 / 100 * (pow(1 + annual_rate / 12 / 100, year * 12) / (pow(1 + annual_rate / 12 / 100, year * 12) - 1))) + 0.01;
n = (year * 12) - 3;
printf("Principle=%.2f rate=%.2f%% %.3f ", principle, annual_rate, annual_rate / 1200);
printf("Pay/month=%.2f Years=%d %d", payment, year, year * 12);
printf(" ");
printf(" ");
printf(" Month Principle Interest $ to principle Prin Balance");
printf(" -------------------------------------------------------------------------- ");
int i = 1;
while (principle > 0)
{
principal = principle;
interest_accrued = principle * monthly_rate;
principle = principle + interest_accrued - payment;
toprinciple = payment - interest_accrued;
if ((i<4) || ((i>(year * 12 - 3)) && (i <= (year * 12))))
{
printf(" %d $%.2f $%.2f $%.2f $%.2f", month, principal, interest_accrued, toprinciple, principle);
}
month++;
i++;
}
printf(" ------------------------------------------------------------------------- ");
return 0;
}
Explanation / Answer
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
int main(void)
{
double principle, toprinciple, principal;
double annual_rate;
double monthly_rate;
double interest_accrued;
double payment = 1;
int month = 1;
int year, n;
char myname[40] = "Jordan";
char username[40];
char ch;
//title
do
{
printf("******************************************************************************** ");
printf("*******************************MORTGAGE CALCULATOR****************************** ");
printf("******************************************************************************** ");
printf(" "); //creates a blank line
printf(" ");
printf("Welcome to my Mortgage program! My name is %s. ", myname);
printf("Please enter your name. ");
scanf_s("%s", username, 40);
printf(" Enter principle amount of the loan, %s: ",username);
scanf_s("%lf", &principle);
printf(" Enter annual interest rate,%s (ex:5%%) ",username);
scanf_s("%lf", &annual_rate);
printf(" %s, Please enter the term in years (ex. 20) and press ENTER ",username);
scanf_s("%d", &year);
printf(" ");
printf(" ");
monthly_rate = annual_rate / 1200;
payment = (principle*annual_rate / 12 / 100 * (pow(1 + annual_rate / 12 / 100, year * 12) / (pow(1 + annual_rate / 12 / 100, year * 12) - 1))) + 0.01;
n = (year * 12) - 3;
printf("Principle=%.2f rate=%.2f%% %.3f ", principle, annual_rate, annual_rate / 1200);
printf("Pay/month=%.2f Years=%d %d", payment, year, year * 12);
printf(" ");
printf(" ");
printf(" Month Principle Interest $ to principle Prin Balance");
printf(" -------------------------------------------------------------------------- ");
int i = 1;
while (principle > 0)
{
principal = principle;
interest_accrued = principle * monthly_rate;
principle = principle + interest_accrued - payment;
toprinciple = payment - interest_accrued;
if ((i<4) || ((i>(year * 12 - 3)) && (i <= (year * 12))))
{
printf(" %d $%.2f $%.2f $%.2f $%.2f", month, principal, interest_accrued, toprinciple, principle);
}
month++;
i++;
}
printf(" ------------------------------------------------------------------------- ");
month=1;
printf("Do you want to run again (Y/N)");
scanf("%c",&ch);
}while(ch!='N');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.