Mercurial > x11calc
diff 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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/calculate.cpp Sun Oct 04 12:56:43 2026 -0500 @@ -0,0 +1,20 @@ +#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; + } +} +
