Tip Calculator
Splits a restaurant bill, tip included.
- Level
- Beginner
- Topic:
- First steps
- Concepts:
- Input & output
- Variables
- Math
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
Several Leer inputs feed a chain of calculations. Redon rounds a number, and the * 100 then / 100 trick keeps exactly two decimals.
Code
Algoritmo CalculadoraPropina Definir cuenta, porcentaje, propina, total, porPersona Como Real Definir personas Como Entero Escribir "Total de la cuenta:" Leer cuenta Escribir "Porcentaje de propina (por ejemplo 10):" Leer porcentaje Escribir "¿Entre cuántas personas se divide?" Leer personas propina <- cuenta * porcentaje / 100 total <- cuenta + propina porPersona <- total / personas Escribir "Propina: $", propina Escribir "Total: $", total // Redon redondea al entero más cercano; así dejamos dos decimales Escribir "Cada persona paga: $", Redon(porPersona * 100) / 100FinAlgoritmoFlowchart
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.
Total de la cuenta:User answer: 1250Porcentaje de propina (por ejemplo 10):User answer: 10¿Entre cuántas personas se divide?User answer: 4Propina: $125Total: $1375Cada persona paga: $343.75
Challenge
If someone types 0 people, show a warning instead of dividing.
Show hint
Wrap the porPersona calculation in Si personas > 0 Entonces ... SiNo ... FinSi.
Related examples
Personal Greeting
Asks for your name and age, and answers with both.
BeginnerFibonacci Sequence
Prints the first terms of the Fibonacci sequence.
BeginnerHello World
Your first algorithm: print a couple of messages on screen.
Beginner