Skip to content
ExamplesEspañolWorkspace →

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

coffee-menu.psc · 26 lines
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    FinSiFinAlgoritmo

Flowchart

Each block in the flowchart matches one instruction in the code.

Algoritmo MenuCafeteria123De Otro ModoSíNoAlgoritmo MenuCafeteriaAlgoritmo MenuCafeteriaDefinir opcion, cantidad Como EnteroDefinir opcion, cantidad ComoEnteroDefinir precio Como RealDefinir precio Como RealEscribir "1. Café $35"Escribir "1. Café $35"Escribir "2. Té $28"Escribir "2. Té $28"Escribir "3. Chocolate $40"Escribir "3. Chocolate $40"Escribir "Elige una bebida:"Escribir "Elige una bebida:"Leer opcionLeer opcionSegun opcion Haceropcionprecio <- 35precio <- 35precio <- 28precio <- 28precio <- 40precio <- 40precio <- 0precio <- 0Si precio = 0 Entoncesprecio = 0Escribir "Esa opción no está en el menú."Escribir "Esa opción no estáen el menú."Escribir "¿Cuántas quieres?"Escribir "¿Cuántas quieres?"Leer cantidadLeer cantidadEscribir "Total: $", precio * cantidadEscribir "Total: $", precio *cantidadFinAlgoritmoFinAlgoritmo

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.

Open in Codoritmo
  • Can I Vote?

    Tells you whether you can vote or how many years you have left.

    Beginner
  • Body Mass Index

    Computes your BMI and classifies it as underweight, normal and so on.

    Intermediate
  • Parking Fee

    Charges every started hour, with a daily maximum.

    Intermediate