Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions write a c program to solve the following problem. Upload your sourc

ID: 3790829 • Letter: I

Question

Instructions write a c program to solve the following problem. Upload your source code file to Canvas. The file name must be of the form hwloop your name.c Substitute your first and last name for "your name" in the file name. Example: Student's name is Sparky Watts. The file name is hwloop sparky watts.c Problem Statement create a program that calculates twelve month's interest and principle loan balance. Your program will ask the user for the starting principle balance, annual interest rate, and monthly payment amount. Your program will verify the input is reasonable, as described in the Error checking section below. After obtaining reasonable the program will process 12 months of payments. The will show the accrued interest and updated loan balance after each month's payment. The total interest paid and total payment amounts for the 12 month period will also be calculated and displayed. Your program output should resemble the output below. AUsers williidialDesktoplhw04MbinlDebuglhw04.exe Enter loan anount: 32000.00 Enter annual interest rate 7.99 Enter monthly payment 752.84

Explanation / Answer

#include <stdio.h>
#include <math.h>

int main()
{
double loan_amount = 0;
printf("Enter loan amount :");
if (scanf("%lf", &loan_amount) != 1)
{
printf("Please enter loan amount correctly ");
return -1;
}

if (loan_amount < 500)
{
printf("Loan amount should be greater than 500 ");
return 1;
}

if (loan_amount > 100000)
{
printf("Loan amount should be less than 100000 ");
return -1;
}

printf("Enter annual interest rate: ");
double interest_rate;
if (scanf("%lf", &interest_rate) != 1)
{
printf("Please enter interest rate correctly ");
return -1;
}

if (interest_rate < 0 || interest_rate > 8.99)
{
printf("Interest rate should be in range of 0 to 8.99 ");
return -1;
}


double monthly_payments;
printf("Enter monthly payment: ");
if (scanf("%lf", &monthly_payments) != 1)
{
printf("Please monthly payment correctly ");
return -1;
}
double first_month_interest = (loan_amount * interest_rate)/(12*100);
if (monthly_payments < first_month_interest)
{
printf("Monthly payment should be greater than %f ", first_month_interest);
return -1;
}

double total_interest = 0;
double total_paid = 0;


printf(" ");
printf("Begin Monthly End ");
printf("Loan Accured Payment Loan ");
printf("Balance Interest Amount Balance ");
printf(" ");
int i;
for(i = 0; i <= 12; i++)
{
printf("%0.2f ", loan_amount);
double interest = (loan_amount*interest_rate)/(1200);
printf("%0.2f ", interest);
printf("%0.2f ", monthly_payments);

loan_amount = loan_amount + interest;

if (loan_amount < monthly_payments)
{
total_paid -= loan_amount;
loan_amount = 0;
printf("%0.2f ", loan_amount);
break;
}
else
{
loan_amount -= monthly_payments;
total_paid += monthly_payments;
}
printf("%0.2f ", loan_amount);
total_interest += interest;
}
printf(" ");
printf("Annual total %.2f %.2f ", total_interest, total_paid);
return 0;
}