insert
Code:
My Code
#include<stdio.h>
main()
{
int a,b,c=0;
while(c!='#')
{
printf("please enter a new sequence\n");
a=getchar() - '0';
b=getchar() - '0';
c=getchar();
if(c=='*')
{
int product=a*b;
printf("(%d) * (%d) = (%d) \n",a,b,product);
}
if(c=='/')
{
int divider=a/b;
printf("(%d) / (%d) = ( %d)\n",a,b,divider);
}
if(c=='+')
{
int add = a+b;
printf("(%d) + (%d) = (%d)\n",a,b,add);
}
if(c=='-')
{
int subtract=a-b;
printf("(%d) - (%d) = (%d)\n",a,b,subtract);
}
}
printf("good bye");
}
I have to write code that terminates the program when '#' is included which I have done and when I type in 34+
it should display 3+4=7 and same with 34* it should display 3*4=12 where my error lies is that when I run the program through the while loop it gives me
please enter a new sequence
34+
3 + 4=7
please enter a new sequence
34-
please enter a new sequence
34-
please enter a new sequence
please enter a new sequence
34-
please enter a new sequence
34-
3-4=-1
Can anyone tell me why it is like that and how to fix it im a confused C programmer