Well as far as I know (because I'm only a beginner too) "nx" can never be a letter, because the nx variable type is an int. This means that nx can only store integer values in that scope.
If you made it a char instead of an int then it would be able to store letters and numbers, but it would only be able to store one at a time (so if you try and store 'ab' in a char, it will only store 'b').
Also, doesn't your compiler throw a spazz if your main function doesn't return an int?
do {
std::cout << "Type 5: ";
std::cin >> nx;
}
while (nx != 5 && nx == "B" ); /* this won't work because nx == "B"
will not be checked cos expesion before && is true and it should be 'B' I think :) */
MY CODE
1 2 3 4 5
do {
std::cout << "Type 5: ";
std::cin >> nx;
}
while (nx != 5 );
The DooD, no, since it's VOID main(), it doesn't require return 0, that would be if I'd put INT main() instead, that would require return 0. Since it's not a complicated program I don't have to inform the system about the result of my program.
Thanks, changing it to char helped. However if I type 5k or k5 or any other letter (not number)
it prints "Type 5: " two times. How do I prevent that?
void main is non-standard, C++ requires int main.
As The DooD said, you need to read a character if you want to check whether it's a letter ( using isalpha function )
If instead want to read an integer and skip invalid input (like letters or any other non-numeric character), see http://www.cplusplus.com/forum/articles/6046/