I've been writing a roman numeral converter off and on for several months. I just decided today to fool around with it some more. The program works as long as the user enters the roman numeral correctly, so I'm working on a function thats supposed to handle errors when the user enters bad data. Anyway, I'm having trouble with the OR-operator ( || )
here's a segment..
void errorp(char a[])
{
int count=0;
while(a[count] != '\0'){
if(a[count] != 'I' || 'V' || 'X' || 'L' || 'C' || 'M' || 'D'){
printf("Waffles!\n");
}
count++;
}
}
See, the idea is that when you enter something that's not part of a roman numeral, you'll get the "Waffles!" message. But when I type in a valid roman numeral, I still get the waffles message. Is that not correct usage of the || operator?
When I type in something like X for example, I expect it to go... "OK, the first spot in this array isn't equal to char I, V, L, C, M, D, however, it is equal to char X, so I won't print the waffles message." but it doesn't do that. =P
here's a segment..
void errorp(char a[])
{
int count=0;
while(a[count] != '\0'){
if(a[count] != 'I' || 'V' || 'X' || 'L' || 'C' || 'M' || 'D'){
printf("Waffles!\n");
}
count++;
}
}
See, the idea is that when you enter something that's not part of a roman numeral, you'll get the "Waffles!" message. But when I type in a valid roman numeral, I still get the waffles message. Is that not correct usage of the || operator?
When I type in something like X for example, I expect it to go... "OK, the first spot in this array isn't equal to char I, V, L, C, M, D, however, it is equal to char X, so I won't print the waffles message." but it doesn't do that. =P