Lab — Calculator menu (console)
Learn by programming: follow each step, write your own code, then apply it to the course assignment.
What you will build
Console program with menu, functions, and flow control (Partial I).
-
1 Calculator CMake project
Create `calculadora/` with `CMakeLists.txt` and `main.cpp`. Reuse the structure from [first program](/en/tutoriales/primer-programa/). -
2 Operation functions
Implement `sumar`, `restar`, `multiplicar`, and `dividir` taking two `double` values. Review [Functions](/en/fundamentos/funciones/) if needed.double dividir(double a, double b) { if (b == 0) throw std::invalid_argument("division entre cero"); return a / b; } -
4 Validate input
If the user chooses divide and the second operand is 0, show a clear message without crashing. Repeat the menu until exit is chosen. -
5 Manual test
Test add, subtract, multiply, valid divide, and divide-by-zero. Save screenshots or console output to review before Partial I.