dimanche 30 mars 2014

C++ Random in Array - Need to replace numbers 22 and 33 with 0


Vote count:

0




I made a 4x4 matrix, where the values are random numbers from 15 to 35:



int rand_range(int min, int max) {
return rand() / (RAND_MAX + 1.0) * (max - min + 1) + min; }

int _tmain(int argc, _TCHAR* argv[]) {
int arr[4][4];
int arr2[4][4];

srand(time(NULL));
for(arr[4][4] = 0; arr[4][4] < 4; arr[4][4]++)
{
int arr[22] = {0};
for(arr2[4][4] = 0; arr2[4][4] < 4; arr2[4][4]++)
{
cout << " " << rand_range(15, 35);
}
putchar('\n');
}

system("pause");
return 0; }


And it's working. But I need to make a change. I want to replace numbers 22 and 33 with 0. So, if the generated random number is 22 for example, it should be printed as 0. How can I do that in this example? Thank you.



asked 51 secs ago






Aucun commentaire:

Enregistrer un commentaire