In: Computer Science
‘A Home For You’ is a company that provides financing for
purchasing a home. All mortgage
applicants must first be approved. All approved applicants are then
required to make a deposit on the
home loan to cover the various applicable fees. The following
information is entered for each
applicant:
name
loan amount
age (A valid age is between 18 and 55 inclusive)
monthly income (monthly income > 0 )
credit rating ('G' for good and 'B' for bad)
house owner (True if applicant owns home and False
otherwise)
Permanent job. (True if applicant has a permanent job and False
otherwise)
The following conditions are used to process the mortgage
application:
Invalid age or income will result in the mortgage application
being denied.
Everybody in the appropriate age range and with good credit will
have their application
approved.
For those with a valid age and income and with bad credit rating,
their application will
be approved if they own their own house AND have a permanent job OR
if they have a permanent job AND their monthly income is 3 times or
greater than the mortgage
amount.
The following schedule is used to determine the required deposit
for approved loan
applications:
Loan Amount ($) Deposit
Less than $25,000 5% of loan amount
$25,000 - $49,999 $1,250 + 10% of loan amount
$50,000 – 100,000 $5,000 + 25% of loan amount
Loans in excess of $100,000 are not allowed.
Write a program, using C, which will process the loan application
for FIVE (5) applicants. The
program should first determine whether the loan is approved and
then determine the required deposit
if the loan has been approved. The output should be the applicant’s
name, the loan amount and the
required deposit or an appropriate message if the loan has been
denied.
NB: Display the total number of approved and total number of
unapproved loans.
The Code for the program is given below.
main.c
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
float calcDepo(int loanAmount)
{
float amt=0;
if(loanAmount<=25000)
{
return (loanAmount * 0.05);
}
else
if(loanAmount>25000 && loanAmount<= 49999)
{
amt = loanAmount * 0.10;
amt += 1250;
}
else
if(loanAmount>=50000 && loanAmount<= 100000)
{
amt = loanAmount * 0.25;
amt += 5000;
}
}
int main()
{
bool arr[2] = {false, true};
int count=0,passed=0,rejected=0;
int loanAmt,age,income,house,job;
float depo=0;
char rating[2],ratG[] = "G",ratB[] = "B",name[30];
while(count<5)
{
printf("Enter details : \n");
printf("Name : ");
scanf("%s",name);
printf("Loan Amount: ");
scanf("%d",&loanAmt);
printf("Age : ");
scanf("%d",&age);
printf("Monthly Income : ");
scanf("%d",&income);
printf("Credit Rating : ");
scanf("%s",rating);
printf("House Owner 1=true , 0 = false: ");
scanf("%d",&house);
printf("Permanent job 1= true, 0 = false ");
scanf("%d",&job);
if((age >= 18 && age <= 55) && (income
>0))
{
if(loanAmt < 100000)
{
depo = calcDepo(loanAmt);
if(strcmp(rating,ratG)==0)
{
passed++;
printf("\n\n");
printf("Name : %s",name);
printf("\nLoan Amount : %d ",loanAmt);
printf("\nDeposit %.2f",depo);
printf("\nApproved\n\n");
}
else
if(strcmp(rating,ratB)==0)
{
if((house == 1 && job == 1) || (job == 1 && income
>= (3 * loanAmt) ))
{
passed++;
printf("\n\n");
printf("Name : %s",name);
printf("\nLoan Amount : %d ",loanAmt);
printf("\nDeposit %.2f",depo);
printf("\nApproved\n\n");
}
else
{
printf("Application Rejected !");
rejected++;
printf("\n\n");
}
}
}
else
{
printf("Application Rejected !");
rejected++;
printf("\n\n");
}
}
else
{
printf("Application Rejected !");
rejected++;
printf("\n\n");
}
count++;
}
printf("\n \n \nTotal Passed %d",passed);
printf("\nTotal Rejected %d",rejected);
return 0;
}
Output