Hey all,
I'm using the code below and similar to validate user entry but can't seem to get it to work...
NOTE_LENGTH is declared as an integer, previously..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// GO BACK HERE IF BAD ENTRY..
DURATION_AGAIN:
cout << "Note Length (1=BAR | 2=HALF | 4=1/4th (Beat) | 8=1/8th | 16=1/16th): ";
cin >> NOTE_LENGTH;
// **************************************************
// CHECK FOR CORRECT ENTRY (NOTE LENGTH)..
// **************************************************
// IF: CHECK LENGTH OF ENTERED NOTE VALUE..
if (NOTE_LENGTH != 1 || NOTE_LENGTH != 2 || NOTE_LENGTH != 4 || NOTE_LENGTH != 8 || NOTE_LENGTH != 16 || isalpha(NOTE_LENGTH))
{
cout << "Not a correct value.." << endl;
goto DURATION_AGAIN;
}
// END IF..
| |
What's supposed to happen is allow only 1, 2, 4, 8 or 16 to be entered. But when either one of the correct responses is entered, it passes the if and displays the cout and then with the goto, cycles round again.
When a string or alpha character is entered, the whole thing blows up. The cout msg just loops madly up and down he screen and i have to close the program.
I can't see what could be wrong with the code though, although i'm still a rookie.
Any ideas? especially a better validation technique please :)
Can i declare NOTE_LENGTH as an array like:
int NOTE_LENGTH[5] = {1,2,4,8,16};
...or something like that and have the contents as a sort of allowed entry list?
Paul..