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: 3788632 • Letter: W

Question

Write a program that displays a menu and asks the user to pick one of the options. The program should run continuously until the user selects quit. Make sure to validate using the proper 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 Payment= Rate* (1 + Rate)/((1 + Rate)* L 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:

Explanation / Answer

C program

#include<stdio.h>
#include<math.h>
void vendingMachine(); // function for vendingMachine
void loan();// function for loan
int main()
{
   int ch,ext =1;
   while(ext)
   {// creating the manu
      printf(" _______MANU________ ");
      printf(" 1. Vending Machine ");
      printf(" 2. Loan ");
      printf(" 3. Quit ");
      printf("Pick one of the options: ");
      scanf("%d",&ch);// get option
      switch(ch)
      {
         case 1:
                 vendingMachine();
                 break;
         case 2:
                 loan();
                 break;
         case 3:
                 ext =0;
       }
    }
    return 0;
}
void vendingMachine()
{
   int p,b,c;
   printf(" Enter price of item: ");
   scanf("%d",&p);
   printf("You brought an item for %d cents and gave me a dollar so your change is ",p);
   b = 100-p;
   c = b/25;
   printf("%d quarters ",c);
   b = b-c*25;
   c = b/10;
   printf("%d dimes, and ",c);
   b = b-c*10;
   c = b/5;
   printf("%d nickel. ",c);
}

void loan()
{
   double L,Rate,payment,PdBk,IP,N;
   printf(" Enter the Loan Amount: ");
   scanf("%lf",&L);
   printf("Enter the interest rate: ");
   scanf("%lf",&Rate);
   printf("Ente the Number of Payments: ");
   scanf("%lf",&N);
   Rate = Rate/(12*100);
   payment = Rate*L/(1-1/(pow(1+Rate,N)));
   PdBk = payment*N;
   IP = PdBk-L;
   printf("%-50s $ %20f ","Loan Amount:",L);
   printf("%-50s   %20f ","Monthly Interest Rate:",Rate);
   printf("%-50s $ %20f ","Number of Payments:",N);
   printf("%-50s $ %20f ","Monthly Payment:",payment);
   printf("%-50s $ %20f ","Amount Paid Back:",PdBk);
   printf("%-50s $ %20f ","Interest Paid:",IP);
}


OUTPUT


       _______MANU________
   1. Vending Machine
   2. Loan
   3. Quit
Pick one of the options: 1

Enter price of item: 45
You brought an item for 45 cents and gave me a dollar so your change is
2 quarters
0 dimes, and
1 nickel.


       _______MANU________
   1. Vending Machine
   2. Loan
   3. Quit
Pick one of the options: 2

Enter the Loan Amount: 10000
Enter the interest rate: 12
Ente the Number of Payments: 36
Loan Amount:                                       $         10000.000000
Monthly Interest Rate:                                           0.010000
Number of Payments:                                $            36.000000
Monthly Payment:                                   $           332.143098
Amount Paid Back:                                  $         11957.151533
Interest Paid:                                     $         1957.151533


       _______MANU________
   1. Vending Machine
   2. Loan
   3. Quit
Pick one of the options: 3

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