Hi. I wonder why this doesn't work.
I expected to see ch1 and ch3 are numbers but it shows they are operators....
How can I make this work?
#include <iostream>
using namespace std;
void isItNumber( char *ch )
{
if( strcmp( ch, "*" ) || strcmp( ch, "/" ) || strcmp( ch, "%" ) || strcmp( ch, "+" ) || strcmp( ch, "-" ) )
{
cout << "ch is an operator\n" << flush;
}
else
{
cout << "ch is a number\n" << flush;
}
}
int main()
{
char *ch1 = "123", *ch2 = "*", *ch3 = "-123", *ch4 = "-";
cout << ch1 << " " << ch2 << " " << ch3 << " " << ch4 << endl;
isItNumber( ch1 );
isItNumber( ch2 );
isItNumber( ch3 );
isItNumber( ch4 );
return 0;
}