Question
I need help getting it to be continous . After it displays the output for the user. I want it to ask the user if
I need help getting it to be continous . 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. And if they choose NO, to end the program. Please help me.
It's a Mortgage calculator program.
My code is here
#include "stdafx.h" #include
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\t\t rate=%.2f%%\t\t %.3f ", principle, annual_rate, annual_rate / 1200); printf("Pay/month=%.2f\t\tYears=%d\t\t\t %d", payment, year, year * 12); printf(" "); printf(" "); printf(" Month\tPrinciple\tInterest\t\t$ to principle\t 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\t$%.2f\t$%.2f\t\t\t$%.2f\t\t$%.2f", month, principal, interest_accrued, toprinciple, principle); } month++; i++; }
printf(" ------------------------------------------------------------------------- ");
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started