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:

  1. accountnum <= 9999
  2. accountnum >= 100000 && accounttype != 'r'
  3. accounttype != 'r'
  4. accounttype != 'b'
  5. 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:

  1. accountnum <= 9999
  2. accountnum >= 100000
  3. accounttype != 'r' && accounttype != 'r' && accounttype != 'b' && accounttype != 'b'

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -