-
unreachable code
<< split from http://cboard.cprogramming.com/c-pro...-eloquent.html >>
i have issue with this program when it runs it shows the error of unreachable code plz anyone tell me how to solve this error in c langugae
Code:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
float num1,num2,add,sub,mul,div;
char op,ans;
printf("Enter the number and operation which you want to perform:\n");
scanf("%f %c %f",&num1,&op,&num2);
do
{
{
if(op=='+')
{
add=num1+num2;
printf("Resut of addition %f\n",add);
break;
}
else if(op=='-')
{
sub=num1-num2;
printf("Result of subtraction %f\n",sub);
break;
}
else if(op=='*')
{
mul=num1*num2;
printf("Result of multiplication %f\n",mul);
break;
}
else
{
div=num1/num2;
printf("Result of division %f\n",div);
break;
}
printf("Do you want to continue:(y/n):");
scanf("%c",&ans);
}
}
while(ans!='n');
getch();
}
-
Well you don't need break statements inside an if / elseif chain,