Constructing do while loop to handle account numbers not working C++ -
i'm trying use while loop evaluate account numbers. valid account number has have 5 digits , start letters r or b, not case sensitive.
valid account number examples: r90000 b10101 r88888 b77777
invalid account number examples: y90000 r888822
this loop i've made, , can't figure out what's wrong parameters that's causing repeat on , on again, never excepting account number.
char accounttype; int accountnum; cout << "please enter account number." <<endl; cout << ">> "; cin >> accounttype >> accountnum; cout <<endl; { cout << "that not valid account number. please enter account number." <<endl; cout << ">> "; cin >> accounttype >> accountnum; cout <<endl; }while ( (accountnum <= 9999) || (accountnum >= 100000) && (accounttype != 'r') || (accounttype != 'r') || (accounttype != 'b') || (accounttype != 'b') );
any ideas?
your conditions repeating loop any of:
accountnum <= 9999
accountnum >= 100000 && accounttype != 'r'
accounttype != 'r'
accounttype != 'b'
accounttype != 'b'
but every character, @ least 2 of (3), (4), , (5) true, you'll repeat.
you need loop while all of accounttype
checks fail or of accountnum
checks fail. is, of:
accountnum <= 9999
accountnum >= 100000
accounttype != 'r' && accounttype != 'r' && accounttype != 'b' && accounttype != 'b'
Comments
Post a Comment