I've been trying to write a program that asks at end of the calculation if we wish to exit it based on input provided. But if I input n, it waits for another input for it to exit the program and after the second input it exits. Is there any way to avoid this? And also the reason why this happens. Here is the complete code.
#include<stdio.h>
int main()
{
float num1, num2;
char op, cont;
while(1)
{
scanf(" %f %c %f",&num1,&op,&num2);
if (op=='+')
printf("%.3f \n",num1+num2);
else if(op=='-')
printf("%.3f \n",num1-num2);
else if(op=='*')
printf("%.3f \n",num1*num2);
else if(op=='/')
{
if(num2==0)
printf("Look where you put your zeroes\n");
else
printf("%.3f\n",num1/num2);
}
else if(op=='%')
printf("%d\n",(int)num1%(int)num2);
else
{
printf("What was the crap you just entered?\n");
}
printf("Continue using calc?[y/n]");
scanf(" %c\n",&cont);
if (cont=='n')
break;
}
return 0;
}