Home > Back-end >  C learn ing the problems
C learn ing the problems

Time:10-19

#include
#include
#include
#include
using namespace std;
Double eval (string) e
{stack s;
Double k, t, sum;
Int I=e.s considering (), j;
for(j=0; J{if (e [j]=='+' | | e [j]=='*' | | e [j]=='/' | | e [j]=='-')
{t=s.t op ();
s.pop();
K=s.t op ();
s.pop();
If (e [j]=='+') sum=k + t;
If (e [j]=='-') sum=k - t;
If (e [j]=='*') sum=k * t;
If (e [j]=='/') sum=k/t;
Supachai panitchpakdi ush (sum);
}
The else supachai panitchpakdi ush ((double) (e) [j] - 96));
}
Return s.t op ();
}
Int main ()
{int num.
A string of AD;
cin> Num.
for(int i=0; i{getline (cin, AD);
cout}
return 0;
}

Above is the program, some small problems, in the main input statement cin> Num. There is a problem, as long as I removed that line, to num assignment, program that's right, but once I use cin, program error, please answer

CodePudding user response:

Why no one reply, please answer

CodePudding user response:

Int main ()
{
int num;
A string of AD;
cin> Num.
for(int i=0; i{
Getline (cin, AD);

cout}
return 0;
}
Such as you enter 3 + 5-2, num take first character 3, go to the statements (for (int I=0; i CodePudding user response:

Don't use getline, getline automatically filter string at the end of the carriage return, there will be a series of problems

CodePudding user response:

Int main ()
{
int num;
A string of AD;
cin> Num.
getchar();//intercept enter
for(int i=0; i{
Getline (cin, AD);

cout}
return 0;
}


Double eval (string) e
{stack s;
Double k, t, sum;
Int I=e.s considering (), j;
for(j=0; J{if (e [j]=='+' | | e [j]=='*' | | e [j]=='/' | | e [j]=='-')
{t=s.t op ();
s.pop();
K=e [j + 1);
//k=s.t op ();//shielding
//supachai panitchpakdi op ();
If (e [j]=='+') sum=k + t;
If (e [j]=='-') sum=k - t;
If (e [j]=='*') sum=k * t;
If (e [j]=='/') sum=k/t;
Supachai panitchpakdi ush (sum);
}
The else supachai panitchpakdi ush ((double) (e) [j] - 96));
}
Return s.t op ();
}

CodePudding user response:

In theory, should have no problem, if pressed key input, there is a problem, before the execution cycle you can put the value of num, print it out and see if the input is the same with you
  • Related