Arrays and Random function.

I am trying to write a function with an array size 6 and each element of the array is a positive two digit integer. What is wrong with my code?

#include <iostream>
using namespace std;

int main() {

int arr [6];
srand(time(0));
int i;
if (i < 100 && i >= 10);
cout << arr[6];
return i;
}
umm nothing ur just doing it wrong

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
int array[6], i, counter = 0;

srand(time(0));

while(counter < 6)
{
i = rand();

if((i % 2) == 0)
{
array[counter] = i;
counter = counter + 1;
}
}
}
I tried the function that you gave me but when i run the program nothing comes out.

#include <iostream>
using namespace std;

int main() {

int array [6], i, counter = 0;
srand(time(0));
while (counter <6)
{
i = rand();
if ((i % 2) == 0);
}
array[counter] = i;
counter = counter + 1;
return 0;
}
ok i pretty much got it, i just had a question my array if of size 6 and i only get 4 numbers that are two digits, is that how its suppose to be? and how to i space the numbers from the output of the array?

#include <iostream>
using namespace std;

int main() {

int array[6], i, counter = 0;
srand(time(0));
for(i = 0; i<6; i++)
int x = rand() % 89 + 10;
cout << array[i]<< " " << endl;
}
Topic archived. No new replies allowed.