I tried to do a basic calculator using this code I was trying to do this without a switch case but things didnt work out here
#include <stdio.h>
int main()
{
int a,b;
char ch;
printf("a and b:");
scanf("%d%d",&a,&b);
printf("op:");
scanf("%c",&ch);
if(ch=='+')
{
printf("sum:%d",a+b);
}
else if(ch=='-')
{
printf("d:%d",a-b);
}
else if(ch=='*')
{
printf("m:%d",a*b);
}
else if(ch=='/')
{
printf("d:%d",a/b);
}
else
printf("Error");
return 0;
}
This is not giving me the right output
Output:
a and b:2 3
op:Error
+
dash: 3: +: not found