Mercurial > x11calc
annotate calculate.cpp @ 0:12567e0a7670 default tip
initial commit
| author | Yasuri <yasuri@charliesmp.net> |
|---|---|
| date | Sun, 04 Oct 2026 12:56:43 -0500 |
| parents | |
| children |
| rev | line source |
|---|---|
| 0 | 1 #include <stdexcept> |
| 2 #include "calculate.h" | |
| 3 double calculate(double x, double y, char op) { | |
| 4 switch(op) { | |
| 5 default: | |
| 6 throw std::runtime_error("unknown sign"); | |
| 7 case '*': | |
| 8 return x * y; | |
| 9 case '+': | |
| 10 return x + y; | |
| 11 case '-': | |
| 12 return x - y; | |
| 13 case '/': | |
| 14 if (y == 0) { | |
| 15 throw std::runtime_error("cannot divide by 0"); | |
| 16 } | |
| 17 return x / y; | |
| 18 } | |
| 19 } | |
| 20 |
