0% found this document useful (0 votes)
17 views14 pages

C Vending Machine Program Design

The document outlines the design and implementation of a vending machine program in C, which includes product management, transaction handling, and user interaction. It emphasizes the use of algorithms and pseudocode to create a user-friendly interface while addressing areas for improvement such as input validation and modularization. The project aims to enhance problem-solving skills and provide a practical application of computer science concepts in a real-world scenario.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views14 pages

C Vending Machine Program Design

The document outlines the design and implementation of a vending machine program in C, which includes product management, transaction handling, and user interaction. It emphasizes the use of algorithms and pseudocode to create a user-friendly interface while addressing areas for improvement such as input validation and modularization. The project aims to enhance problem-solving skills and provide a practical application of computer science concepts in a real-world scenario.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Design and creation of the machine

vending machine

Integrante: Robles Guzmán Michel Armando


Career: Computer Systems Engineering
Group: 2MSC2
Resumen:
The provided code implements a vending machine program in C. It uses
a Product structure to store information about the products, including
name, price, quantity and expiration status. The program displays a menu of
available products, allows the user to select and purchase products, calculates the
change and update the quantity of available products. The code illustrates the use of
structures, loops and standard input/output. Areas for improvement are highlighted, such as the
input validation and modularization.

Abstract:
This provided code implements a vending machine program in C. It utilizes a Product
structure to store information about products, including name, price, quantity, and
expiration status. The program displays a menu of available products, allows the user to
select and purchase items, calculates change, and updates product quantities. The code
exemplifies the use of structures, loops, and standard input/output. Opportunities for
Enhancement, such as input validation and code modularization, are highlighted.
General objective
Design a system of algorithms and pseudocode that simulates the functioning of a
vending machine capable of selling products and handling transactions efficiently
efficient and precise. The project seeks to create a program that allows the user
select products, enter the necessary money for the purchase, check the balance
available, deliver the selected product and, if necessary, return the change
corresponding.

By achieving this objective, the project will demonstrate the ability to create algorithms and
pseudocode to simulate a typical interaction between a client and a machine
vending machine, providing a close to real experience. Additionally, it is expected that the
the program is easily scalable and adaptable for future improvements or additions
characteristics.

Specific objectives
[Link] the system logic: Create an algorithm that allows the user to interact.
with the vending machine, select products, insert the money, and receive the change
corresponding.

2-. Implement inventory management: Develop an algorithm that controls the


amount of products available in the machine and update the inventory afterwards
each purchase.

3-. Validate the customer's balance: Create an algorithm that checks if the customer's balance is
enough to purchase the selected product and handles it properly
transactions with insufficient balances.

[Link] change correctly: Design an algorithm that calculates and delivers the
exchange for the customer after a purchase, if necessary.

5-. Show relevant information: Implement an algorithm that displays to the client
useful information, such as the product price, available balance, and quantity of
remaining products.

[Link] usability: Ensure that the program is intuitive and easy to use,
clear messages and well-defined options to facilitate user interaction.

7-. Validate and correct errors: Implement mechanisms to detect and handle errors,
such as entering invalid data or selecting unavailable options.

[Link] thorough testing: Test the program with different scenarios and data
for testing to ensure that it works correctly and meets the requirements
established.
[Link] the code: Create clear and concise documentation that explains the
functioning of the algorithm and pseudocode, facilitating its understanding and possible
future expansion or modification.

[Link] performance: Look for ways to improve the algorithm's efficiency,


reduce complexity and ensure an adequate response time for a
smooth user experience.

Justification
The realization of the integrative project is justified for various reasons:

1-. Practical application of algorithms and pseudocode: This project allows for the application
the knowledge of algorithms and pseudocode in a realistic context. The machine
a vending machine is a common scenario in everyday life, and designing an algorithm for
simulating its operation provides a valuable hands-on experience.

2-. Development of problem-solving skills: The design of a system of


Algorithms for a vending machine involves solving different challenges, such as
manage inventory, validate balances and calculate changes. This activity contributes to the
development of problem-solving skills and logical thinking.

3-. Understanding transactions and business logic: By simulating a machine


vending machine, the commercial logic behind the transactions must be taken into account,
such as balance validation and change delivery. This provides a better understanding of
deep understanding of how these types of business interactions work.

[Link] in interactive system design: The project offers the opportunity


to design an interactive system where the user makes decisions and is provided with
relevant information. This promotes the ability to create friendly and useful interfaces.
for the user.

5-. Scalability and adaptability capacity: When developing an algorithm for the
vending machine, it is important to consider scalability to add new ones
products or functionalities in the future. This experience enhances the skills to
design modular and adaptable systems.

6-. Testing and debugging of the algorithm: The completion of the project involves performing
exhaustive testing of the algorithm to ensure its proper functioning and correction
possible errors. This helps strengthen debugging skills and improves quality
of the code.

7-. Awareness of limitations and efficiency: When designing the algorithm, one must take into account
It accounts for the efficiency and optimization of the code to achieve a user experience.
fluid. This practice increases awareness of the importance of efficiency in the
algorithm design.
State of the art
Below are some projects/jobs that are related to this work.

INVENTORY OF VENDING MACHINES USING A LPWAN


National Technological Institute of Mexico in Celaya
Objective:
A system is presented that allows viewing the inventory of machines from the Internet.
vending machines connected to a wide area network of
low power (LPWAN). Each node connects a vending machine to the gateway. The
machine administrator can view the product inventory using a
user interface that runs on a computer connected to the Internet. Each
The LPWAN node consists of an LL-RXR-27 transceiver and an Arduino Due board.
The LPWAN connects to the network server located in Amazon Web Services.

-CONTROL OF A VENDING MACHINE (Polytechnic University of


Valencia):
This work is focused specifically on electronic vending machines,
a growing sector in recent years with a large market worldwide. This
work is motivated by a booming technological future, where a large part of the
Electronic vending machines will be operated using touch devices.
both for the control and maintenance of them by an operator, as well as for
the payment of a product by a customer. Thus, this work seeks to
bring a new perspective to the concept of vending machine that now
we know.

- DEVELOPMENT OF A BUSINESS PLAN FOR MARKETING


OF FOOD THROUGH VENDING MACHINES INSIDE THE
UNIVERSITY OF AZUAY.
This topic has been chosen because there is a need to make available to the
students and teachers a quick and convenient service related to purchasing
consumer products like snacks, cold and hot beverages. For this reason, it
It is important to incorporate the Business Plan that will be developed throughout this.
investigation.

-
Start

Productos: Frituras, Refresco,


Cookies, Chocolate bar, Juice
Peanuts.
Dinero: 1, 2, 5, 10, 20, 50, 100

Wish
acquire a
product

Choose a
product of 1-6

Do you want
choose more
of one
cantdad?
Pay with (only coins
coins/banknote from 1,2,5,10)

(cash only from


20,50,100

The change is of:


Is there change? I can't return

Process
finalized!

Do you want to purchase


another product?

End
Pseudocode (C Language)

#include <stdio.h>

Structure to represent a product


struct Product {
char name[30];
int price;
int quantity;
int caducidad; // 0: no caduca, 1: caducado
};

Function to show the available products menu


void showMenu(struct Product products[], int numProducts) {
printf("Welcome to the vending machine\n");
Available products menu:
--------------------------------
for (int i = 0; i < numProductos; i++) {
if (products[i].expiration == 0) {
%d. %s - Price: $%d
}
}
--------------------------------
}

// Function to check if a product is expired


int isExpired(struct Product product) {
return ([Link] == 1);
}

int main() {
int initial_money = 500;
int total_money = initial_money;

Product array
struct Product products[6] = {
{"Frituras", 10, 10, 0},
{"Refresco", 15, 10, 0},
{"Galletas", 13, 0, 1},
{"Chocolate en barra", 5, 0, 1},
{"Jugo", 12, 10, 0},
{"Cacahuates", 8, 10, 0}
};

int numProducts = sizeof(products) / sizeof(products[0]);

int selected, money_inserted;


Show the product menu
mostrarMenu(productos, numProductos);

Enter the desired product number or 0 to exit:


scanf("%d", &selected);

while (selected != 0) {
if (selected < 1 || selected > numProducts ||
isExpired(products[selected - 1]) {
Invalid option or expired product. Please try again.
} else {
struct Producto *selected_product = &products[selected - 1];

printf("Enter the money to buy %s (Price: $%d): ", selected_product);


>nombre, producto_seleccionado->precio);
scanf("%d", &inserted_money);

if (inserted_money < selected_product->price) {


Insufficient funds. Missing $%d
inserted_money;
} else {
int cambio = money_inserted - selected_product->price;
total_money += selected_product->price;
selected_product->quantity--;
printf("Thank you for your purchase. Here is your %s\n", selected_product);
>name);
if (change > 0) {
Your change is: $%d
}
}
}

Show the product menu again


mostrarMenu(productos, numProductos);

printf("Enter the desired product number or 0 to exit: ");


scanf("%d", &selected);
}

See you later. Come back soon.

return 0;
}
Development
Initial phase
Here, the basic concepts must be understood in order to program (in this case
In C language), the input is first made #include <studio.h> for input and
make the code work.

Subsequently, the data to be used for the coding and execution must be declared.
vending machine, to subsequently use this data to perform the functions
desired.

Implementation of the code


Structure to represent a product: Here data about a product is added so that
it represents their respective attributes.

Structure to represent a product: Here the attributes of each are added.


product first adding the char name[30]; (already with the text that will be written

Function to display the menu of available products: Here we write with the
printf function for

Function to check if a product is expired:

The code is a program in C language that implements a vending machine with


the mentioned characteristics:
Definition of the Product structure: A structure called Product is created that
contains the fields name, price, quantity, and expiration. Each field represents
product information on the machine.

Function showMenu(): A function named showMenu() is defined that takes as


argumentos un arreglo de productos y el número total de productos disponibles. Esta
the function is responsible for displaying the menu of available products in the machine,
excluding those that are expired.

Function isExpired(): A function called isExpired() is defined that receives as


argue a product and check if the expiration field is equal to 1, which means that
the product is expired. Return 1 if it is expired and 0 if it is not.

Main function(): In the main function(), a variable initial_money is declared to


represent the initial money that the machine has and a total_money variable for
keep a record of the total money accumulated from sales.

Product array: A structure array called products is declared.


with 6 elements. Each element represents one of the available products in the
machine.

While loop: The program enters a while loop that repeats until the user
Enter 0 to exit the machine.

Product selection: The user can select a product by entering the number.
corresponding in the menu. It is verified if the option is valid and if the product is not
expired. If the option is invalid or the product is expired, a message is displayed
of error and the menu is displayed again.

Purchase and change calculation: If the option is valid and the product is not expired, the
the program asks the user to enter the money to buy the product. It checks if the
The money submitted is sufficient for the purchase and change is calculated if necessary.
Then the total money record and the inventory of the purchased product are updated.

End of the cycle: After each purchase, the product menu is displayed again.
so that the user can make another purchase or exit the machine.

Mensaje de despedida:Cuando el usuario decide salir de la máquina (ingresando 0), se


muestra un mensaje de despedida.

Subsequently, the code is executed in a program with the C language.


In summary, the code implements a vending machine that allows the user
buy available products, calculate the change, control the inventory and detect
expired products. In addition, it displays information messages in case of errors or
special situations. This is the development of a vending machine with 6
products. If the customer decides to exit, the program ends, and if they continue, the cycle repeats
allowing new purchases to be made until the customer decides to exit.
Problems
At the time of developing the vending machine algorithm, it required a high
care when designing the diagram, and even more regarding the code, likewise, it was achieved
successfully present this project with the purpose of developing what has been learned so that in the
institution is represented as a unit that fulfills education and teaching in the
fundamentals of the career that is being studied.

When developing the vending machine algorithm, it required great care when designing
the diagram, and even more in terms of the code, likewise, it was successfully possible to
present this project in order to develop what was learned so that in the institution is
represented as a unit that complies with the education and teaching in the fundamentals of
the career that is being studied.

Conclusiones
For the formalization of a vending machine, a system has been successfully developed.
efficient and safe to operate and manage the vending machine effectively. Have
analizado los requisitos y regulaciones aplicables y se han implementado las medidas necesarias
to comply with the current regulations.

Through the formalization of the vending machine, the experience of has been improved.
user by providing a friendly and easy-to-use interface. In addition, a system has been implemented
real-time inventory control, which has allowed for the optimization of product replenishment and
ensure their availability.

Security has also been a priority in the project. Mechanisms have been implemented for
authentication and encryption to protect user information, as well as detection systems
of frauds and manipulations.

In summary, the project has been successful in the formalization of a vending machine.
improving its performance, security, and user experience. It is expected that this
implementation serves as a basis for future projects.

For the formalization of a vending machine, it has been possible to develop an efficient and safe
system to operate and manage the vending machine effectively. The applicable requirements and
Regulations have been analyzed and the necessary measures have been implemented to comply.
with current standards.

Through the formalization of the vending machine, it has been possible to improve the user
experience by providing a friendly and easy-to-use interface. In additon, a real-tme inventory
A control system has been implemented, which has made it possible to optimize the replacement of
products and guarantee their availability.
Safety has also been a priority in the project. Authentication and encryption mechanisms have
been implemented to protect user information, as well as fraud and manipulation detection
systems.

In summary, the project has been successful in the formalization of a vending machine, improving
its operation, security and user experience. It is expected that this implementation will serve as the
basis for future projects.

Bibliographic sources
-Luna, J. I.V., Acosta, M. A. L., Guzmán, G. S., Vargas, V. N.T., Rangel,F.J. S., &
Aceves, J.F.C. (2018). Inventory of vending machines using a
LPWAN. National Technology of Mexico, (article made using PHP).
[Link]

-Vela, G., & Carlos, J. (2019). Control of a vending machine. University


Polytechnic University of Valencia.
[Link]

-Priscila Ximena Reinoso Solís, María del Cisne Zúñiga Jácome. (2011).
Development of a business plan for the marketing of food through
of vending machines within the University of Azuay. Cuenca, Ecuador.
University of Azuay Official
[Link]

- Arteaga Gaona Guillermo Devars Caballero Enrique Rangel Acosta Jessica


Esmeralda. (2015). Diseño e Implementación de una Máquina Expendedora
Virtual. Interdisciplinary Professional Unit in Engineering and Technologies
Advanced (UPIITA). Mexico City. Mexico. National Polytechnic Institute.

You might also like