here's what i have so far.
I don't understand where exactly to put the (valid = MY_FALSE;) and the (badInput =
MY_TRUE;) and the (valid = MY_TRUE;).
The directions state that:
Declare a contant for true, use 1 (MY-TRUE)
Declare a contant for false, use 0 (MY-FALSE)
Declare the integer variables valid and badInput and set badIput to MY-FALSE
Each prompt shall:
- Set valid to MY_FALSE
- Loop while badInputand valid are not true
Also my while statements seem to repeat forever after i apply the loan amount.
This program should spit out principal, balance, interest that shoud look like this
----------------------------------------------------------------------------------------------
loan amount: 1000
interest rate: 5.50
points: 1.00
monthly payment: 200.00
starting date: 03/2003
-------------------------------------------------------------------------------------------------
DATE DUE PAYMENT INTEREST PRINCIPAL BALANCE
04/2003 200.00 4.63 195.37 814.63
05/2003 200.00 3.73 196.27 618.36
06/2003 200.00 2.83 197.17 421.36
09/2003 24.25 0.11 24.14 0.00
-----------------------------------------------------------------------------------------------
i have to enter:
loan amount 1000
interest rate 5.50
points 1.00
monthly payment 200.00
starting date 03/2003
#include<stdio.h>
int main(void){
double totalLoan, i, mp, points, totalInterest, currentLoan, loan, principal ;
int month, year, status, q=12;
const int MY_FALSE = 0;
const int MY_TRUE = 1;
int valid = MY_FALSE;
int badInput = MY_FALSE;
while (!valid && !badInput) {
printf ("\n\n *********Amortization Schedule*********\n");
printf(" ---------------------------------------------------\n\n");
// Prompt the user to enter values........
printf("Loan Amount:\n");
status = scanf("%d", &totalLoan);
if (status == 0) {
printf("bad input\n");
badInput = MY_FALSE;
}
while (totalLoan < 0.01 || totalLoan > 100000.00){
printf("ERROR: entered loan amount %d\nLoan must be >= 0.01 and <= 100000\n ",
totalLoan);
}
printf("Interest Rate:\n");
scanf("%d", &i);
while (i <= 0 && i > 20){
printf("ERROR: entered interest rate %d\nInterest rate must be >= 0 and <= 2\n ", i);
}
printf("Points:\n");
scanf("%d", &points);
while (points <= 0 && points > 20){
printf("ERROR: entered %d points\nPoints must be >= 0 and <= 20\n", points);
}
printf("Monthly Payment:\n");
scanf("%d", &mp);
while (mp < 0 && mp > totalLoan){
printf("ERROR: entered interest rate %d\nInterest rate must be >= 0 and <loan\n", mp);
}
printf("Start Month and Year mm/yyyy:\n");
scanf("%d%d", &month,&year);
while (month < 1 && month > 12 || year <= 1899){
printf("ERROR: entered %d%d month/year\nMonth must be between 1 and 12 and year must be
= 1900\n", month, year);
}
valid = MY_FALSE;
if (!badInput){
totalInterest = 0;
totalLoan = loan * (1 + (points / 100));
while (totalLoan > 0) { // Loan is not piad off
i = totalLoan * 1/(100 *q);
i = floor (i * 100.0 + 0.5);
i /= 100.0;
totalInterest += i;
currentLoan = totalLoan + i;
if (currentLoan < mp){
mp = currentLoan;
principal = mp - i;
totalLoan = currentLoan - mp;
}
printf("%d,Loan Amount:\n");
printf("%d,i:\n");
printf("%d,points:\n");
printf("%d,mp:\n");
printf("%d%d,month, year:\n");
printf("DUE DATE PAYMENT INTEREST PRINCIPAL BALANCE, \n");
printf("%d %d %d %d %d,month/year, mp, i, principal, currentLoan \n");
}}}
return (0);
}