Mercurial > x11calc
view calculate.cpp @ 0:12567e0a7670 default tip
initial commit
| author | Yasuri <yasuri@charliesmp.net> |
|---|---|
| date | Sun, 04 Oct 2026 12:56:43 -0500 |
| parents | |
| children |
line wrap: on
line source
#include <stdexcept> #include "calculate.h" double calculate(double x, double y, char op) { switch(op) { default: throw std::runtime_error("unknown sign"); case '*': return x * y; case '+': return x + y; case '-': return x - y; case '/': if (y == 0) { throw std::runtime_error("cannot divide by 0"); } return x / y; } }
