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

Write a program that displays a menu and asks the user to pick one of the option

ID: 3788973 • Letter: W

Question

Write a program that displays a menu and asks the user to pick one of the options. The program should run continuosly until the user selects quit. Make sure to validate using the propger type of loop

   Vending machine
   Loan
   Quit

Upon choosing option 1 do the following

This piece will determine the change that is to be dispensed from a vending machine. An item in the machine can cost anywhere between 25 cents and a dollar, in 5 cent increments (25, 30, 35, …, 90, 95, 100), and accepts only a single dollar bill to pay for the item. For a example a possible sample dialog might be
  
   Enter price of item: 45
   You bought an item for 45 cents and gave me a dollar so your change is
   2 quarters,
   0 dimes, and
   1 nickel.

You can assume all items will be less than one dollar. Validate to make sure that the user has not entered a price more than one dollar.

Upon choosing option do the following:
This piece will calculate the monthly payment on a loan. The monthly payment on a loan may be calculated by the following formula

The user will enter the interest rate, the loan amount and the number of payments. Make sure to use the double data type for your declarations.

For the interest rate, you need to convert it into a monthly interest rate by dividing it by 12 and then further dividing it by 100. For example 12% would become 1% after the calculation.

N is the number of payments

L is the amount of the loan

This is what should be displayed at the end:

       Loan Amount:           $ 10000.00
       Monthly Interest Rate:       1
       Number of Payments:           36
       Monthly Payment:       $ 332.14
       Amount Paid Back       $ 11957.15
       Interest Paid:           $ 1957.15


HINT for formatting: print (“%-50s $ %20f”,”Loan Amount”, L);

Rate (1 Rate)" Payment (1 Rate)" -1)

Explanation / Answer

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

void vending_machine()
{
int ch;
int amt,dimes=10,nickel=5,quater=25,pay;
printf(" Enter price of item: ");
scanf("%d",&amt);
printf(" Your brought an item for %d", amt);
printf(" cents and gave me a dollar. So your change is: ");
pay=100-amt;
quater=pay/25;
pay=pay-(25*quater);
dimes=pay/10;
pay=pay-(10*dimes);
nickel=pay/5;
pay=pay-(5*nickel);
printf("Quaters: %d ",quater);
printf("Dimes: %d ",dimes);
printf("Nickel: %d ", nickel);
}

void loan()
{
double r, loan, p,mul;
int n;
printf ("Enter Loan amount: ");
scanf ("%f", &loan);
printf ("Monthly interest rate: ");
scanf ("%f", &r);
printf ("Number of Payments: ");
scanf ("%d", &n);
mul = pow(1+r, n);
p=(loan * mul * r) / (mul - 1);
printf (" Loan amount: $%0.2f",loan);
printf (" Monthly interest rate: %.0f",r);
printf (" Number of Payments: %d",n);
printf (" Monthly Payment: $%.2f", p);
printf (" Amount Paid Back: $%.2f", p*n);
printf (" Interest Paid:: $%.2f", (p*n)-loan);
}

int main()
{
int ch;
while(1)
{
printf("****OPTION***** ");
printf("1. Vanding machine. 2. Loan. 3. QUIT. ");
printf("Enter choice--> ");
scanf("%d",&ch);
if(ch==3) break;
switch(ch)
{
case 1: //vending machine
vending_machine();
break;
case 2: //loan
loan();
break;
}
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote