Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void)
- {
- float value1, value2;
- char operator, ch;
- printf("Type in your expression.n");
- scanf_s("%f %c %f", &value1, &operator, &value2);
- //This version works...
- /*
- scanf_s("%f", &value1);
- ch = getchar();
- scanf_s("%c", &operator);
- scanf_s("%f", &value2);
- */
- switch (operator)
- {
- case '+':
- printf ("%.2fn", value1 + value2);
- break;
- case '-':
- printf("%.2fn", value1 - value2);
- break;
- case '*':
- printf("%.2fn", value1 * value2);
- break;
- case '/':
- if (value2 == 0)
- printf("Division by zero.n");
- else
- printf("%.2fn", value1 / value2);
- break;
- default:
- printf("Unknown operator.n");
- break;
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment