Can some help me with my Default:
It is printing the error message but at end of message is giving a decimal value for the char sign.
How do I stop this from happening?
#include <stdio.h>
char sign;
int x, y;
int main() {
printf("Choose:\n");
printf("a) Addition\n");
printf("b) Subtraction\n");
printf("c) Division\n");
printf("d) Multiplication\n");
scanf("%c", &sign);
sign = 'f'; // For testing the Default
printf("Enter two numbers:\n");
scanf("%d%d", &x, &y);
x = 12; // Test for x
y = 4; // Test for y
/*Print out their numbers inside the math_function*/
printf("%d\n", math_function(x, y));
return 0;
}
int math_function(int x, int y) {
switch(sign) {
case 'a':
return x + y;
case 'b':
return x - y;
case 'c':
return x / y;
case 'd':
return x * y;
default:
printf("'%c' is an invalid choice ", sign);
}
return 0;
}