### Do/While Loop not working

Can someone help me understand why this do/while loop isn't working. I want it to stop when at least one random number in each one of the vectors is the same as another random number selected.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100`` `````` #include #include #include #include #include #include using namespace std; int main(void) { vector vectorJ(4); vector vectorK(4); vector vectorL(4); vector vectorM(4); vector vectorN(4); for(int i=0;i<5;i++) { vectorJ[i] = rand() % 15 + 1; //random number from 1 to 15 vectorK[i] = rand() % 15 + 16; //random number from 16 to 30 vectorL[i] = rand() % 15 + 31; //random number from 31 to 45 vectorM[i] = rand() % 15 + 45; //random number from 46 to 60 vectorN[i] = rand() % 15 + 61; //random number from 60 to 75 } int a = 0; int b = 0; int c = 0; int d = 0; int e = 0; int xyz = 0; do { char question; cout << "Type 'A' to select random number... "; cin >> question; if(question == 'a' || question == 'A') { int randomN = rand() % 75 + 1; //draws random number from 1 -75 for(int i=0;i<5;i++) //if random number drawn is the same as the random numbers first inserted into the vectors, it changes that vectors random number to 99 { if(randomN == vectorJ[i]) { vectorJ[i] = 99; } if(randomN == vectorK[i]) { vectorK[i] = 99; } if(randomN == vectorL[i]) { vectorL[i] = 99; } if(randomN == vectorM[i]) { vectorM[i] = 99; } if(randomN == vectorN[i]) { vectorN[i] = 99; } } } if((vectorJ[0] || vectorJ[1] || vectorJ[2] || vectorJ[3] || vectorJ[4]) == 99) { a = 1; } if((vectorK[0] || vectorK[1] || vectorK[2] || vectorK[3] || vectorK[4]) == 99) { b = 1; } if((vectorL[0] || vectorL[1] || vectorL[2] || vectorL[3] || vectorL[4]) == 99) { c = 1; } if((vectorM[0] || vectorM[1] || vectorM[2] || vectorM[3] || vectorM[4]) == 99) { d = 1; } if((vectorN[0] || vectorN[1] || vectorN[2] || vectorN[3] || vectorN[4]) == 99) { e = 1; } if((a == 1) && (b == 1) && (c == 1) && (d == 1) && (e == 1)) { xyz = 1; } } while(xyz == 0); } ``````
Last edited on
I'd say it's more than likely your if conditions.

They'd need to look more like this:
 ``123`` ``````if ( vectorJ[0] == 99 || vectorJ[1] == 99 || // etc. ``````

Or, more simply...
 ``12345678910`` ``````for ( int i=0; i < 5; i++ ) { if( vectorJ[i] == 99 ) a = 1; if( vectorK[i] == 99 ) b = 1; // etc. }``````
Worked! Thanks a lot
Topic archived. No new replies allowed.