我试图让 scanf 以数字的形式接收用户的输入,然后使用我要求的两个数字来执行一些简单的数学运算,我遇到的问题是,无论我输入什么数字,他们总是只是吐出 1 任何帮助将不胜感激
包括
int main(int argc, char const *argv[])
{
float in1,in2,value;
char c;
printf("Enter the operation of your choice:\n");
printf("A. add S. subtract\n");
printf("M. multiply D. divide\n");
printf("Q. quit\n");
c=getchar();
while( c !='Q' && c!='q')
{
printf("please enter your first number:");
scanf("%g", &in1);
printf("%g\n",in1 );
printf("please enter your second number:");
scanf("%g", &in2);
printf("%g\n",in2 );
if(c == 'S' || c =='s')
if(in2 == 0)
{
printf("you have selected subtration however\n");
printf("the value you entered was 0\n");
printf("please enter a value greater than 0\n");
scanf("%lg",&in2);
}
if(c == 'a' || c == 'A')
{
value = in1+in2;
printf("%lg + %lg = %lg\n",in1,in2,value );
}
if(c == 's' || c == 'S')
{
value = in1-in2;
printf("%lg - %lg = %lg\n",in1,in2,value );
}
if(c == 'm' || c == 'M')
{
value = in1*in2;
printf("%lg * %lg = %lg\n",in1,in2,value );
}
if(c == 'd' || c == 'D')
{
value = in1/in2;
printf("%lg / %lg = %lg\n",in1,in2,value );
}
if (c !='Q' && c !='q')
{
printf("Enter the operation of your choice:\n");
printf("A. add S. subtract\n");
printf("M. multiply D. divide\n");
printf("Q. quit\n");
}
c=getchar();
}
return 0;
}