Q.Create an equivalent of four function calculator. The program should request the user to enter two numbers and an operator. It should carry out specified arithmetic operation on the two numbers( using switch case).After displaying the result, the program should ask the user if he/she wants to do another calculation.If 'y', make it perform another operation.
The solution I tried
{
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c;
char sign,answer;
clrscr();
do
{
printf("Enter your choice of operator\n");
printf("+ for addition\n");
printf("- for subtraction\n");
printf("* for multiplication\n");
printf("/ for division\n");
scanf("%c",&sign);
printf("Enter two numbers\n");
scanf("%f %f",&a,&b);
switch(sign)
{
case '+': c=a+b;
printf("The addition is %f\n",c);
break;
case '-': c=a-b;
printf("The subtraction is %f\n",c);
break;
case '*': c=a*b;
printf("The product is %f\n",c);
break;
case '/': c=a/b;
printf("The division is %f\n",c);
break;
}
printf("Do you want to continue?(y or no)\n");
scanf("%c",&answer);
}while(answer!='n');
}
}
Problem is that although everything else works fine, when the question "Do you want to continue ?(y or no)" is asked, it doesn't take in the answer and straight away goes ahead to provide the options again.Help!!!!!