Your for loop (lines 8-9) are your problem. At the moment you are simply changing the value of random_integer 20 times before moving into your do while loop. You need to assign a value to random_intger everytime you iterate through your do-while loop. Note however, that you should only call srand() once.
Also, have you realised that in your first post you have: random_integer = (rand()%50)+1;
Wheras in your second you have: random_integer = (rand()%5)+1;