I have to do a 4 function calculator for class with the do...while loop. With the option of ending the program after the while by either entering 'y' or 'n'. However the program automatically loops without seeking input to restart or not.
/* This is a four function calculator with multiplication, addition, substraction and division*/
#include<stdio.h>
#include<stdlib.h>
main()
{
float a,b,c;
char sign,answer;
do
{
printf("Enter your choice of operator\n");
printf("+ for addition\n");
printf("- for substraction\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 %.1f\n",c);
break;
}
case '-':
{
c=a-b;
printf("The substraction is %.1f\n",c);
break;
}
case '*':
{
c=a*b;
printf("The multiplication is %.1f\n",c);
break;
}
case '/':
{
c=a/b;
printf("The division is %.1f\n",c);
break;
}
}
printf("Do you want to continue? (y or n)\n");
scanf("%c",answer);
}while (answer !='N');
system ("pause");
}