Store Inventory
Records the stock of each product and flags what to restock.
- Level
- Intermediate
- Topic:
- Arrays
- Concepts:
- Input & output
- Arrays
- Para
- Si
Run, change and debug this example in your browser.
What you'll learn
Two parallel arrays work together: productos[i] and stock[i] describe the same product. A counter (aReponer) tells you whether anything ran low.
Code
Algoritmo InventarioTienda Definir productos Como Caracter Definir stock, i, aReponer Como Entero Dimension productos[5], stock[5] productos[1] <- "Arroz" productos[2] <- "Leche" productos[3] <- "Pan" productos[4] <- "Huevos" productos[5] <- "Café" Para i <- 1 Hasta 5 Hacer Escribir "Unidades de ", productos[i], ":" Leer stock[i] FinPara aReponer <- 0 Escribir "Productos para reponer (menos de 10 unidades):" Para i <- 1 Hasta 5 Hacer Si stock[i] < 10 Entonces Escribir "- ", productos[i], " (quedan ", stock[i], ")" aReponer <- aReponer + 1 FinSi FinPara Si aReponer = 0 Entonces Escribir "Ninguno. ¡Todo en orden!" FinSiFinAlgoritmoFlowchart
Each block in the flowchart matches one instruction in the code.
Sample run
This is what the program shows when it runs. The answers typed by the user are highlighted.
Unidades de Arroz:User answer: 24Unidades de Leche:User answer: 6Unidades de Pan:User answer: 15Unidades de Huevos:User answer: 3Unidades de Café:User answer: 40Productos para reponer (menos de 10 unidades):- Leche (quedan 6)- Huevos (quedan 3)
Challenge
At the end, show the total number of units in the store.
Show hint
Add stock[i] to an accumulator inside one of the Para loops.
Related examples
Bubble Sort
Sorts random numbers by swapping neighbors, and stops as soon as they're in order.
IntermediateSelection Sort
Finds the smallest of the remaining numbers and puts it in its place.
IntermediateInsertion Sort
Inserts each number among the sorted ones, like arranging cards in your hand.
Intermediate