1. ## Problem validating

hello, I'm working on a roman numeral converter, but I'm having trouble validating that the user input is valid. Even when I input a valid roman number the following function returns false. Can someone be kind enough to point out what I'm doing wrong, and also I'm confused as how to validate that the roman number is valid, for example XIDMXM is not valid.

Code:
```bool isValidSigns(char roman)
{
bool valid = true;
int i = 0;

while(roman[i] != '\0')// && valid != false)
{
cout<<"= "<<roman[i]; //for testing
if(roman[i] != 'M' ||'D' ||'C' ||'L'||'X' ||'V' ||'I')
{
valid = false;
}
i++;
}

return valid;
}``` 2. Code:
`if(roman[i] != 'M' ||'D' ||'C' ||'L'||'X' ||'V' ||'I')`
is the problem. It only compares roman[i] with 'M'.

If roman[i] is not equal to 'M', the result is true and else is checked nothing happens (so valid is set to false).

If roman[i] is equal to 'M', the next step is to evaluate the expression 'D'. 'D' is a non-zero integral value, so evaluates to true (non-zero). This means the test always drops through to setting valid to be false.

What you probably intend is this
Code:
`if(roman[i] != 'M' && roman[i] != 'D' && roman[i] != 'C' && roman[i] != 'L'  && roman[i] != 'X' && roman[i] != 'V' && roman[i] != 'I')` 3. Thank you for the help, i tried using && but not && and != and now that I look at the code you provided it makes sense. 4. you could use an std::string containing "MDCLXVI", and search for the character in that string using std::string::find(). 5. Originally Posted by Elkvis you could use an std::string containing "MDCLXVI", and search for the character in that string using std::string::find().
Well so far i'm getting the output I was expecting. I thought about using a string but felt more comfortable using char[]. I need more practice with string as I moved from C to C++. 6. Originally Posted by Kinto Well so far i'm getting the output I was expecting. I thought about using a string but felt more comfortable using char[]. I need more practice with string as I moved from C to C++.
Yes, because std::string is much harder to work with, right?

Code:
```
int main( void )
{
std::string
txt;
txt = "foo";
txt += "bar";
if( txt == "foobar" )
/* do something*/;
return 0;
}```
Versus:

Code:
```
int main( void )
{
char
txt[ 1024 ];
strncpy( txt, "foo", sizeof str );
strncat( txt, "bar", sizeof str );
if( strncmp( txt, "foobar", sizeof str ) == 0 )
/* do something*/;
return 0;
}``` 7. When people ask me why I drive standard over an automatic, I simply tell that I get bored and like switching gears. well enough of bad analogies thanks for the suggestions and the sample code. Popular pages Recent additions 