Write a program in c that simulates a soft drink machine

Assignment Help Computer Engineering
Reference no: EM132208493

Question :

Write a program in 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

Reference no: EM132208493

Questions Cloud

Write a program called split in java that reads a text file : Write a program called Split in Java that reads a text file, in.txt, that contains a list of positive integers.
Calculate the average of a group of test scores : Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped.
Print all ratings and the average rating in a button event : Write a program in C# Windows Form that creates a ProfessorRating class consisting of professor ID and three ratings.
Write the reference where you get the information : Analyze the repercussions that the two world wars had on the global society and the US and PR. Remember to write the reference where you get this information.
Write a program in c that simulates a soft drink machine : 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.
Write the function using a loop and without a loop : Add a main to each of the two programs to fully test them out and do at least 5 test run for each program.
Draw the indifference curves and budget line of that worker : Assume optimum labor time of a worker is positive. Draw the indifference curves and budget line of that worker. Show the optimum level of his labor time.
Calculate the greatest common divisor of any finite set : Write a program to calculate the greatest common divisor of any finite set of integers.
Write a program to calculate the hashing table of input data : Write a program to calculate the hashing table of input data. The program reads from the standard input the table size k.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd