Random numbers

So i've this problem with this array

It is assumed that the values ​​of the array must be random, but the only number listed is 897.
This have to work with only these two libraries.

Thank you guys.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  //Uso de arreglos en C++
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
  int array[70];
  int numA;
  numA =rand() % 1001;

    cout << "Introduce 70 numbers " << endl;
  for (int i = 0 ; i < 70 ; i++)
         {
      cout << " values for array["<<i<<"]" << endl;
      cout<<numA<<endl;
      }

    cout<<"Even numbers"<<endl;
        for (int i=0; i<70; i++){
        if (i/2 ==0 )
        return i;
        }

    cout<<"Odd numbers"<<endl;
        for (int i=0; i<70; i++){
            if (i/2 !=0)
            return i;
            }

  return 0;
}
You need to seed a rand() function, however you will have to add a library:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <time>

int main()
{
 srand(time(0)) // <- add this so you will get random number
  int array[70];
  int numA;
  numA =rand() % 1001;

    cout << "Introduce 70 numbers " << endl;
  for (int i = 0 ; i < 70 ; i++)
         {
      cout << " values for array["<<i<<"]" << endl;
      cout<<numA<<endl;
      }

    cout<<"Even numbers"<<endl;
        for (int i=0; i<70; i++){
        if (i/2 ==0 )//<- Need a % symbol, not /
        if (i%2 ==0 )
        return i;
        }

    cout<<"Odd numbers"<<endl;
        for (int i=0; i<70; i++){
            if (i/2 !=0)//<- Need a % symbol, not /
             if (i%2 !=0)
            return i;
            }

  return 0;
}



Also for the Odd and Even numbers, you need to use the % modulus symbol instead of / divide. The % symbol gives you the remaind while the / just divides and thus will not give you an odd or even number just a value.
Last edited on
Topic archived. No new replies allowed.