Coffee Shop Menu
Pick a drink from the menu and get the total to pay.
- Level
- Beginner
- Topic:
- Decisions
- Concepts:
- Input & output
- Segun
- Si
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
Segun ... Hacer picks a case based on the option, and De Otro Modo catches anything that isn't on the menu. Then a Si decides whether to continue the order.
Code
Algoritmo MenuCafeteria Definir opcion, cantidad Como Entero Definir precio Como Real Escribir "1. Café $35" Escribir "2. Té $28" Escribir "3. Chocolate $40" Escribir "Elige una bebida:" Leer opcion Segun opcion Hacer 1: precio <- 35 2: precio <- 28 3: precio <- 40 De Otro Modo: precio <- 0 FinSegun Si precio = 0 Entonces Escribir "Esa opción no está en el menú." SiNo Escribir "¿Cuántas quieres?" Leer cantidad Escribir "Total: $", precio * cantidad 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.
1. Café $352. Té $283. Chocolate $40Elige una bebida:User answer: 3¿Cuántas quieres?User answer: 2Total: $80
Challenge
Add a fourth drink to the menu, for example a $32 juice.
Show hint
Print the new menu line and add a 4: case inside the Segun.
Related examples
Can I Vote?
Tells you whether you can vote or how many years you have left.
BeginnerBody Mass Index
Computes your BMI and classifies it as underweight, normal and so on.
IntermediateParking Fee
Charges every started hour, with a daily maximum.
Intermediate