Home > Back-end >  [for] about a complicated calculator
[for] about a complicated calculator

Time:11-20

said few words directly on the code, the problem in the following,
 # include & lt; stdio.h> 
#include
# define N 10000
Float Jia (void);
Float Jian (void);
Float Cheng (void);
Float Chu (void);
Float Storage (void);
Int Kb (void);
Char menu (void)
{
Char way;
Printf (" ___________________________________ \ n ");
Printf (" M E N U \ N ");
Printf (" a. b. an addition operation subtract \ n ");
Printf (c. d. multiplication division \ n ");
Printf (" e. history record (data) within 5 f stop \ n ");
Printf (" please enter numerical model:...... \n");
Printf ("  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄  ̄ \ n ");
For (;; )
{
Printf (" shuru ");
Way=getchar ();
While (getchar ()! )
='\ n'continue;
If (' a '& lt;=way & amp; & Way & lt; )
='f'{
break;
}
The else
{
Printf (" input mode is not correct, please enter again: \ n ");
}
}
The return way;
}
Int main ()
{
Char way;
Float result=0;
Way=menu ();
While (way! )
='f'{
The switch (way)
{
Case 'a' : Jia (); break;
Case 'b' : Jian (); break;
Case 'c' : Cheng (); break;
Case 'd' : Chu (); break;
Case 'e' : Storage (); break;
Default: printf (" error "\ n");
break;
}
break;
}
}
Float Jia (void)
{
Float x1, x2, result;
Printf (" please enter the first number: \ n ");
Scanf_s (" % f ", & amp; The x1);
Printf (" please enter the second number: \ n ");
Scanf_s (" % f ", & amp; X2);
Result=x1 + x2;
Printf (" result=%. 5 f \ n ", result);
Kb ();
return result;
}
Float Jian (void)
{
Float x1, x2, result;
Printf (" please enter the first number: \ n ");
Scanf_s (" % f ", & amp; The x1);
Printf (" please enter the second number: \ n ");
Scanf_s (" % f ", & amp; X2);
Result=x1 - x2.
Printf (" result=%. 5 f \ n ", result);
Kb ();
return result;
}
Float Cheng (void)
{
Float x1, x2, result;
Printf (" please enter the first number: \ n ");
Scanf_s (" % f ", & amp; The x1);
Printf (" please enter the second number: \ n ");
Scanf_s (" % f ", & amp; X2);
Result=x1 * x2;
Printf (" result=%. 5 f \ n ", result);
Kb ();
return result;
}
Float Chu (void)
{
Float x1, x2, result;
Printf (" please enter the first number: \ n ");
Scanf_s (" % f ", & amp; The x1);
Printf (" please input the second number (divisor) : \ n ");
Scanf_s (" % f ", & amp; X2);
If (x2==0)
{
While (x2==0)
{
Printf (" divisor must be non-zero, please input again: \ n ");
Scanf_s (" % f ", & amp; X2);
}
}
Result=x1 and x2;
Printf (" result=%. 5 f \ n ", result);
Kb ();
return result;
}
Float Storage (void)
{
0.0 f return;
}
Float Storage (float c)
{
Float a, [N].
For (int I=0; i <=5; I++)
{
A [I]=c;
}
Return a, [N].
}
Int Kb (void)
{
Char way;
int a;
Printf (" press [space] to return to the menu bar \ n ");
While (1)
{
A=GetKeyState (VK_SPACE);
If (a & lt; 0)
{
Way=menu ();
break;
}
}
return 0;
}

Problem: when I run the first time after press the space back to the menu bar in the calculation, the second input any model number display "pattern is not correct," is this why? Online and so on, is very urgent,

CodePudding user response:

The second type, menu function there should be a way to get the value '\ n' return, so is not correct,
  • Related