Question
home / study / engineering / computer science / questions and answers / write a program in c(not c+) that simulates a soft ... Your
home / study / engineering / computer science / questions and answers / write a program in c(not c+) that simulates a soft ...
Your question has been answered
Let us know if you got a helpful answer. Rate this answer
Question: Write a program in C(not C+) that simulates a soft...
Bookmark
Write a program in C(not C+) that simulates a soft drink machine. The program should use a structure that stores the following data:
Drink Name
Drink Cost
Number of Drinks in the Machine
The program should create an array of structures (maximum 20). The elements should be initialized by reading all data from a file called "drinks.txt". The first line in the data file contains the number of drink records. See sample data below.
Each time a program runs, it should load the data from the file and enter into a loop that displays the list of drinks and their cost on the screen. If the user selects a drink, he or she will next enter the amount of money that is to be inserted into the machine. The program should display the amount of change that would be returned and subtract one from the number of drinks left in the machine. If the user selects a drink that has sold out, a message should be displayed. The loop then repeats. When the user chooses to quit the program, it should display the total amount of money the machine earned and save all the data back into the input file "drinks.txt". Next time the program is run, it will load the new data into the array.
Input Validation: When the user enters an amount of money, do not accept negative values or values greater that $1.00.
Sample Data File (the first entry is the number of soft drinks):
7
Coca Cola
.75
2
Root Beer
.75
5
Grape Soda
.80
20
Cream Soda
.80
18
Mocha Frappuccino
1.00
10
Diet Sprite
.75
1
Nestea Iced Tea
.85
5
Sample Run:
Note that the menu options will change depending on the number of drinks stored in the input file.
1. Coca Cola 0.75
2. Root Beer 0.75
3. Grape Soda 0.80
4. Cream Soda 0.80
5. Mocha Frappuccino 1.00
6. Diet Sprite 0.75
7. Nestea Iced Tea 0.85
8. Quit
Enter your choice:1
Enter the amount of money:1.00
Amount of change: 0.25
1. Coca Cola 0.75
2. Root Beer 0.75
3. Grape Soda 0.80
4. Cream Soda 0.80
5. Mocha Frappuccino 1.00
6. Diet Sprite 0.75
7. Nestea Iced Tea 0.85
8. Quit
Enter your choice: 2
Enter the amount of money: 5.00
Illegal amount
1. Coca Cola 0.75
2. Root Beer 0.75
3. Grape Soda 0.80
4. Cream Soda 0.80
5. Mocha Frappuccino 1.00
6. Diet Sprite 0.75
7. Nestea Iced Tea 0.85
8. Quit
Enter your choice: 8
Total collected: $0.75
Required functions:
1. Write a function that displays all drink choices
2. Write a function that removes the new-line character from the end of a string
3. Write a function that stores all the data back to the file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started