From 6904f56a8798daf1fc2c6ec58398ff86c6894764 Mon Sep 17 00:00:00 2001 From: Shreyansh Gupta <78748065+shreyan55@users.noreply.github.com> Date: Mon, 18 Oct 2021 19:17:28 +0530 Subject: [PATCH] Add files via upload --- simplecalculator.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 simplecalculator.c diff --git a/simplecalculator.c b/simplecalculator.c new file mode 100644 index 0000000..a403378 --- /dev/null +++ b/simplecalculator.c @@ -0,0 +1,29 @@ +#include +int main() { + char op; + double first, second; + printf("Enter an operator (+, -, *, /): "); + scanf("%c", &op); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (op) { + case '+': + printf("%.1lf + %.1lf = %.1lf", first, second, first + second); + break; + case '-': + printf("%.1lf - %.1lf = %.1lf", first, second, first - second); + break; + case '*': + printf("%.1lf * %.1lf = %.1lf", first, second, first * second); + break; + case '/': + printf("%.1lf / %.1lf = %.1lf", first, second, first / second); + break; + // operator doesn't match any case constant + default: + printf("Error! operator is not correct"); + } + + return 0; +}