So I made this loop program in c that is basically a calculator, but i am getting issues with it in vs code(scanf isn’t working) and i tried it in online compiler but something’s off and the program terminates after clicking y.
#include<stdio.h>
int main(){
int a;int b;char c;char ch="y";
while(ch=='y'){
printf("enter the first number\n");
scanf("%d\n",&a);
printf("enter the second number\n");
scanf("%d\n",&b);
printf("select your operation\n");
scanf("%c\n",&c);
if(c=='*'|| c=='x'){
printf("product is %d\n",a*b);
}
else if(c=='/'){
printf("quotient is %d\n",a/b);
}
else if(c=='-'){
printf("difference is %d\n",a-b);
}
else if(c=='+'){
printf("sum is %d\n",a+b);
}
else{
printf("invalid input\n");
}
printf("do you want to continue y or n");
scanf("%c\n",&ch);
}
return 0;
}
here is the output:
A C lang noob btw (had python in high school but now struggling in C)
