Question

In: Computer Science

C language <stdio.h> (Decisions only) (else if and Switch statements) A bank wants an application to...

C language <stdio.h> (Decisions only) (else if and Switch statements)

A bank wants an application to help in the loan approval process and has asked us to create it for them. Write a program to ask the user for the loan amount, the annual interest rate (as a percentage, not as a decimal), the length of the loan (in years), and the gross monthly income of the applicant. Validate the inputs per below, and if invalid, inform the user and end the program:

 Loan amount must be greater than $0.00

 Annual interest rate must be greater than 1.0% and less than 20.0%

 Loan duration must be between 1 year and 30 years

 Monthly income must be greater than $0.00

After all the inputs have been validated, calculate and display the monthly loan payment and the total interest for the loan based on the following formulas:

payment = p * r / (1 – (1 + r)-n )

total interest = n * payment – p

where:

 p = the loan amount

 r = monthly interest rate (annual rate / 12)

 n = loan duration (in months)

Finally, determine if the applicant qualifies for the loan.

 If the loan payment is less than or equal to 20.0% of the monthly income, they definitely qualify

 If the loan payment is greater than 20.0% and less than or equal to 25.0% of the monthly income, it will be tight, but they qualify

 If the loan payment is greater than 25.0% and less than or equal to 30.0% of the monthly income, they qualify (but the loan probably shouldn’t be approved)

 If the loan payment is more than 30.0% of the monthly income, they do not qualify

Create constants for any numbers used that do not change (0, 1, 12, 20, 30, & 100) and the loan qualification levels (20.0%, 25.0%, & 30.0%), and use the constants in the validation conditions and error messages, in conversions from percentages to decimal (and vice versa) and conversions from years to months.

Display all dollar amounts with a dollar sign and 2 decimal places, and all percentages to 1 decimal place followed by a percent sign.

Example Run #1: (bold type is what is entered by the user)

Enter the amount of the loan: $100000.00

Enter the annual interest rate (8.0 = 8.0%): 4.0

Enter the length of the loan (in years): 30

Enter your monthly gross income: $3000.00

The monthly payment is: $xxx.xx (~$480.00)

The total interest is: $xxxxx.xx (~$71,870.00)

The monthly payment is less than or equal to 20.0% of your gross monthly income.

You are definitely approved for the loan!

Example Run #2:

Enter the amount of the loan: $200000.00

Enter the annual interest rate (8.0 = 8.0%): 4.0

Enter the length of the loan (in years): 30

Enter your monthly gross income: $3000.00

The monthly payment is: $xxx.xx

The total interest is: $xxxxxx.xx

The monthly payment must be less or equal to 30.0% of your gross monthly income.

I’m sorry – You do not qualify for the loan.

Example Run #3:

Enter the amount of the loan: $-50000

The mortgage amount must be greater than $0.00.

The example runs show EXACTLY how your program input and output will look.

Solutions

Expert Solution

************BankLoan.c**************

#include<stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
const int ze = 0;
const int o = 1;
const int tw = 12;
const int twe = 20;
const int th = 30;
const int hu = 100;

const float twper =20.0;
const float tw5per =25.0;
const float thper =30.0;

float p,ar,r,ginco, n,ylen,tot_in,pay;
int flag;
printf("Enter the amount of the loan: $");
scanf("%f",&p);
if(p<=ze)
{
printf("Loan amount must be greater than $0.00");
exit(0);
}
printf("\nEnter the annual interest rate (8.0 = 8.0%):");
scanf("%f",&ar);
if(ar<o && ar>twe)
{
printf("Annual interest rate must be greater than 1.0% and less than 20.0%");
exit(0);
}
r=ar/(tw*hu);
printf("\nEnter the length of the loan (in years):");
scanf("%f",&ylen);
if(ylen<o && ylen>th)
{
printf("Loan duration must be between 1 year and 30 years");
exit(0);
}
n=ylen*tw;
printf("\n Enter your monthly gross income: $");
scanf("%f",&ginco);
if(ginco<=ze)
{
printf("Monthly income must be greater than $0.00");
exit(0);
}

pay=(p*r*pow(r+1,n))/(pow(r+1,n)-1);//replace the given formula with this one and it will work

tot_in=n*pay-p; //this is coreect

printf("The monthly payment is: $ %0.2f",pay);
printf("\n The total interest is: $ %0.2f",tot_in);

float j=twper/hu;
float k=tw5per/hu;
float l=thper/hu;

//for wach logic we set a value for flag

if(pay<=j*ginco)
{
flag=1;
}
else if(pay>j*ginco && pay<=k*ginco)
{
flag=2;
}
else if(pay>k*ginco && pay<=l*ginco)
{
flag=3;
}
else if(pay>l*ginco)
{
flag=4;
}

//using the flag values in switch case
switch(flag)
{

case 1:
printf("\n The monthly payment is less than or equal to 20.0% Of your gross monthly income.");
printf("\n You are definitely approved for the loan!");
break;
case 2:
printf("\nThe monthly payment is greater than 20.0% and less than or equal to 25.0% of the monthly income.");
printf("\n It will be tight, but you qualify");
break;
case 3:
printf("\n The monthly payment is greater than 25.0% and less than or equal to 30.0% of the monthly income.");
printf("\n You qualify (but the loan probably shouldn’t be approved)");
break;
case 4:
printf("\n The monthly payment must be less or equal to 30.0% of your gross monthly income.");
printf("\n I’m sorry – You do not qualify for the loan.");
break;

}

}

**********************If this answer helps you please give like Thank YOU!!*********************

Updated answer fully working code


Related Solutions

LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu...
LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu to choose from – 1. Convert temperature input from the user in degrees Fahrenheit to degrees Celsius 2. Convert temperature input from the user in degrees Celsius to degrees Fahrenheit 3. Quit. Formulae you will need: C = (5 / 9) * (F-32) and F = (9/5) * C + 32 1. Use functions to accomplish 1 and 2 above. 2. Use at least...
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature...
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature to Fahrenheit temperature. The formula for converting Celsius temperature into Fahrenheit temperature is:    F = (9 / 5) * C + 32 Create integer constants for the 3 numbers in the formula (9, 5, and 32).  Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. Convert the 9 to a double when converting the temperature (use type casting). Have a...
C language <stdio.h> use double and const Write a program that asks the user for the...
C language <stdio.h> use double and const Write a program that asks the user for the radius of a circle (as a double) and displays the diameter, circumference, and area of the circle. Use a constant of 3.14159 as the value of pi. Have a blank line between the input and the output. Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. The formulas needed are: diameter = 2 * radius circumference = 2 *...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); 2. Write a Constructor for the TrafficLight class that sets stopLight value to “red”, waitLight to “yellow” and goLight to “green”?
Introduction to java: Gambling Objectives: •Performing decisions using if and switch statements. •Using relational and logical...
Introduction to java: Gambling Objectives: •Performing decisions using if and switch statements. •Using relational and logical operators •Working with random numbers Write an application that simulates a gambling slot machine. In the application, perform the following tasks: 1. Prompt the player to enter the amount of money that the player is willing to gamble. 2. Create three random numbers in range from one to four to represent three of the following four objects (Apple, Orange, Cherry and Pineapple). 3. Compare...
C code only, not C++ or anything else // This program accepts the chest size from...
C code only, not C++ or anything else // This program accepts the chest size from the customer // and returns the proper shirt size as well as the price. // function prototype void check_size_price(int size_val, char *size_char, int *price); #include <stdio.h> int main() { int chest_size; //input - entered chest size char size_str; //output - size (S/M/L) int p; //output - price // validation loop for the input – the chest size must be a positive integer // Call...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
C Mini Project is a mini application that could be developed using C language that involves...
C Mini Project is a mini application that could be developed using C language that involves the concepts of arrays, functions, read and write data techniques. Based on your creativity, you are required to plan, design and develop a mini application for an organisation. You may choose to from the list below or propose your own mini application: 1. Customer Billing System 2. Employee Record System 3. Contact Management System 4. Appointment Management System 5. Attendance Record System Your responsibility...
Use C language , pointer limit use //#include <stdio.h> //#include <stdlib.h> //#include <time.h> For example, I...
Use C language , pointer limit use //#include <stdio.h> //#include <stdlib.h> //#include <time.h> For example, I have random array [4,2,7,1,9,8,0]. Sort the array's index but cannot change the position of item in the array, if you copy the array to a new array, you also cannot change the item's position in array. The index now is[0,1,2,3,4,5,6] The output should be[6,3,1,0,2,5,4]
Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number;...
Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number; Scanf (“%d”, & number); if (number % 2 ==0) { printf (“Even\n”); } else { printf(“Odd\n”); } Return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT