### vector trouble

The goal is to create 25 random numbers in between 0 and 99 and place them into two lists which tells the user if they are even or odd. I cant get it to put the numbers into even and odd vectors.
 ``12345678910111213141516171819202122232425262728293031323334353637383940`` ``````#include #include using namespace std; int random(int v1) //generates 25 random numbers between 0 and 99 { for (int count=0; count<25; count++) //counts up to 25 so only 25 numbers are generated { v1 = rand() % 100; // v1 is the range 0 to 99 cout<evennum(25); //this is the vector for even numbers they each could have 25 numbers stored vectoroddnum(25); // this is the vector for odd numbers they each could have 25 numbers stored // displays the 25 numbers int remainder = num % 2; // determines if the remainder is even if (remainder==0) //if the number is even it is added into the even vector { evennum[even] = num; //takes in the number of odd numbers and stores them in evennum even++; //counts the number of even numbers evennum; //outputs the numbers } else //if the number is not even it is placed in the odd vector { oddnum[odd] = num; //takes in the number of odd numbers and stores them in oddnum odd++; //count the number of odd numbers oddnum; //outputs the numbers } return(0); }``````
Last edited on
Tell us what about it isnt working. Also, surround your code in code blocks.Its the button under Format: that looks like <>.
You have several problems with your code.

Line 8: You termination condition on the for loop is wrong. It should be `count < 25`

Line 10: You generate the random number, but don't store it anywhere. The value of v1 is lost on the next iteration of the loop.

Line 22: You calculate remainder from num, but num is uninitialized.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.

I fixed line 8 thank you I probably wouldn't have seen it for a while. I initialized num it's passing the random number back to the code.

It now does output but just a line of numbers. I am not quite sure how to store the random number
Topic archived. No new replies allowed.