I am trying to do a simple program where i will first give the operation name and 2nd will give two number. Based on the operation name it will show me result. It will be done inside a infinite for loop.
But Here my problem is that the code is working for first iteration, from 2nd it is not working properly. gets() not taking input.
I have given the source here please where the mistake i have done.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char command[80];
float i,j;
for( ; ; )
{
printf("what operation you want???\n");
gets(command);
if( !strcmp(command,"quit") )
{
break;
}
printf("enter first number :\n");
scanf("%f",&i);
printf("enter second number :\n");
scanf("%f",&j);
if(!strcmp(command,"add"))
printf("%f\n",i+j);
else if(!strcmp(command,"divide"))
printf("%f\n",i/j);
else if(!strcmp(command,"multiply"))
printf("%f\n",i*j);
else if(!strcmp(command,"subtract"))
printf("%f\n",i-j);
else printf("unknown command\n");
}
return 0;
}