Hamish
2013-06-25 02:07:19 UTC
What is wrong with the following code and are there any helpful tips or anything people can help me with??
#include
int math_function(int x, int y);
int main()
{
int x, y;
char sign;
printf("Choose:\n");
printf("a) Addition\n");
printf("b) Subtraction\n");
printf("c) Division\n");
printf("d) Multiplication\n");
scanf("%c", &sign);
printf("Enter two numbers:\n");
scanf("%d%d", &x, &y);
/*Print out their numbers inside the math_function*/
printf("%d\n", math_function(x, y));
return;
}
char sign;
int math_function(int x, int y)
{
switch(sign)
{
case 'a':
return x + y;
break;
case 'b':
return x - y;
break;
case 'c':
return x / y;
break;
case 'd':
return x * y;
break;
/*Default statement*/
default:
printf("You entered an invalid choice\n");
}
}
Thanks!