Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int math(int a, int b, char selection) {
- int result;
- switch (selection) {
- case 'a':
- result = a + b;
- break;
- case 's':
- result = a - b;
- break;
- case 'm':
- result = a * b;
- break;
- case 'd':
- result = a / b;
- break;
- }
- return result;
- }
- int main() {
- int num1 = 0;
- int num2 = 0;
- int result = 0;
- char selection;
- printf("Enter first number: ");
- scanf("%i", &num1);
- printf("Enter second number: ");
- scanf("%i", &num2);
- printf("n[a] Addn[s] Subtractn[m] Multiplyn[d] DividennWhich one: ");
- scanf("%c", &selection);
- result = math(num1, num2, selection);
- printf("%i", result);
- return 0;
- }
- printf("Enter second number: ");
- scanf("%i", &num2);
- you can't see that, but it's there
- V
- > Enter second number: 3n
- scanf("%c", &selection);
- scanf(" %c", &selection);
- printf("n[a] Addn[s] Subtractn[m] Multiplyn[d] DividennWhich one: ");
- int ret = scanf("%c", &selection);
- printf("Scanf I think failed. Return value is: %d. Selection is: %c (%d)n",
- ret, selection, selection);
- Scanf I think failed. Return value is: 1. Selection is:
- (10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement