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

In this project VENDO. We are going to use Structs and maybe Enums that we learn

ID: 3560143 • Letter: I

Question

In this project VENDO. We are going to use Structs and maybe Enums that we learned about today.

Your job is to write code to simulate a vending machine with at least ten products in it. Stock the vending machine with three of each item. Stock the coin machine with three of each coin. To acquire items from the vending machine you must first ask the user which item they wish to purchase. If item requested is out of stock report that item is not available. If item is in stock ask them to report on the coins or bills they placed in the machine. Once they give you the amount of coins or bills, you must report on whether or not the translaction is possible. If it is not possible return their coins and bills and advise them to use correct change . If it is possible vend the item and make change using the minimum number of coins. Announce the calorie content of the item to make them feel guilty (or not). Report on the inventory of the vending machine. Report on the inventory of the coin machine. Ask for another transaction?

Plan

OUTPUT

SAMPLE OUTPUT (User input in RJed)

Welcome to Jerry's Virtual Vending Machine

Choose item from our fabulous choices

1)      Tootsie Roll 30 cents (3)

2)      Hostess Dolly Cup Cakes 125 cents (3)

3)      Rolo Roll candy    85 cents (3)

4)      Dr Maroon Soda   150 cents (3)

5)      Gummy Squid   65 cents (3)

6)      Open Hostility Energy Drink    325 cents (3)

7)      Tums 2-pack   50 cents (3)

8)      Blind Mother Fields Cookies 175 cents (3)

9)      Frozen Penguin Cola   100 cents (3)

10)   Campus Quad Sardines   225 cents (3)

Your choice:  3

Enter dollars: 1

Enter quarters: 0

Enter dimes: 0

Enter nickels: 0

Item vended Rolo Roll Candy 600 calories

Change Below

1 dime

1 nickel

Coin Inventory 4 Dollars , 3 Quarters, 2 Dimes, 2 Nickels

Do you wish another transaction Y/N :Y

Welcome to Jerry

Explanation / Answer

001   #include <stdio.h>
002     
003   int beverages();
004   void chosen(int choice);
005   float drink_cost(int choice);
006     
007   int main()
008   {
009   int user_at_machine = 1;
010     
011     
012   while(user_at_machine)
013   {
014   int choice;
015   /* in an actual program floats and doubles
016   would not be used for monetary values
017   as they are not always exact */
018   float item_cost;
019   float money;
020   float change;
021     
022   /* display items and get users choice */
023   choice = beverages();
024     
025   /* display pick */
026   chosen(choice);
027     
028   /* getting money could be in a function */
029   if(choice >= 1 && choice <= 20)
030   {
031   /* get drinks cost */
032   item_cost = drink_cost(choice);
033     
034   printf("Enter your money: ");
035   scanf(" %f", &money);
036   printf(" ");
037     
038   if (money > 0)
039   {
040   printf("ACCEPTED! ");
041   change = money - item_cost;
042   printf("Your change is %.2f", change);
043   }
044   else
045   {
046   printf("NOT ACCEPTED! ");
047   }
048   printf(" ");
049     
050   /* get newline in stream */
051   getchar();
052   /* get character to pause */
053   getchar();
054   }
055   else
056   {
057   /* is user quitting ? */
058   if(choice == 99) {
059   user_at_machine = 0;
060   }
061   }
062     
063   } /* end while */
064     
065   return 0;
066   }
067     
068     
069   /* display beverages and get pick */
070   int beverages()
071   {
072   int choice;
073     
074   printf("---------------------- ");
075   printf("Name list of beverage: ");
076   printf(" ");
077   printf("1. Pepsi"); printf(" RM1.00 ");
078   printf("2. Miranda"); printf(" RM1.00 ");
079   printf("3. Mountain Dew"); printf(" RM1.00 ");
080   printf("99. Quit");
081   printf(" ");
082     
083   printf("Enter your choice: ");
084   scanf(" %d",&choice);
085     
086   return choice;
087   }
088     
089     
090   /* display users pick */
091   void chosen(int choice)
092   {
093   switch(choice)
094   {
095   case 1:
096   printf("You choose Pepsi"); printf(" RM1.00 ");
097   break;
098   case 2:
099   printf("You choose Miranda"); printf(" RM1.00 ");
100   break;
101   case 3:
102   printf("You choose Mountain Dew"); printf(" RM1.00 ");
103   break;
104   case 99:
105   break;
106   default:
107   printf("Invalid input! ");
108   break;
109   }
110   }
111     
112     
113   /*get drink cost */
114   float drink_cost(int choice)
115   {
116   float cost = 0;
117     
118   switch(choice)
119   {
120   case 1:
121   cost = 1.00;
122   break;
123   case 2:
124   cost = 1.00;
125   break;
126   case 3:
127   cost = 1.00;
128   break;
129   }
130     
131   return cost;
132   }

Thank You
Please Check & Rate

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