Int main ()
{
int x;
Char c1;
Float a, b;
Do
{
The scanf (" % f % c % f ", & amp; A, & amp; C1, & amp; B);
Getchar ();
If (c1=='+')
{
Printf (" a + b=% f ", a + b);
X=0;
}
Else if (c1=='-')
{
Printf (" a - b=% f ", a - b).
X=0;
}
Else if (c1=='*')
{
Printf (" a * b=% f ", a * b);
X=0;
}
Else if (c1=='/')
{
Printf (" a/b=% f ", a/b);
X=0;
}
The else
{
Printf (" please enter the formula contains only addition, subtraction, multiplication, and division \ n ");
X=1;
}
} while (x);
}
Want to ask why, every mistake will print several times "please enter the formula contains only addition, subtraction, multiplication, and division"
CodePudding user response:
You are what's wrong to lose?CodePudding user response:
Where there is a problem? Run again noCodePudding user response:
Doubt the original poster is a problem with the input format, it is recommended that the original poster posted on the test cases,The following input is no problem:
1 + 2
1 * 2
Pay attention to the space between 1 and + or *
CodePudding user response:
Is that if the input is not only the formula contains addition, subtraction, multiplication, and division, he will output many lines of "please enter the formula contains only addition, subtraction, multiplication, and division"CodePudding user response:
While (x) in the x is assignment,And the do... While () loop in the condition of no exit,
CodePudding user response:
Getchar () what is the role of?CodePudding user response:
Enter other don't become infinite loop?