having to face some issue on this program to develop a calculator, i have tried to do the calculation for maths operation before the switch statement. The print result only prompt invalid entry on my default statement after entering the value and maths operation
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
// declare and initialise working storage
char function;
int num1, num2, sum, sub, multi, div, remainder;
// prompt user to enter 2 number
printf("Enter numbers and function: ");
scanf("%d%c%d", &num1, &function, &num2);
// calculation
sum = num1 + num2;
sub = num1 - num2;
multi = num1 * num2;
div = num1 / num2;
remainder = num1 % num2;
// print the result
switch(function)
{
case '+':
printf("The sum is %d\n", sum);
break;
case '-':
printf("The subtraction is %d\n", sub);
break;
case '*':
printf("The multiplication is %d\n", multi);
break;
case '/':
if(num2 ==0)
{
printf("Cannot divide by 0!\n");
}
else
{
printf("The div is %d\n", div);
}
break;
case '%':
if(num2 ==0)
{
printf("Cannot divide by 0!\n");
}
else
{
printf("The remainder is %d\n", remainder);
}
break;
default:
printf("Invalid Entry!!!!!\n");
break;
}
return 0;
}