How to proceed?!?!

I was assigned to write a program that uses parallel vectors and functions which fills each of them with 500 random numbers between 1 and 100. The program is supposed to pass both vectors to a function which will return an integer indicating a count of how many times both vectors had even numbers in the same location. So if vetor01 [0] contained 4 and vector02 [0] contained 12, you would add one to count. If vector01 [1] contained 3 and vector02 [1] contained 4, you would not add one to count

example of how it should look like: The vectors contain 128 cells where both values are even.

what I have so far, although I don't think I'm on the right track

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
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

// function prototype
void count(int x);

int main()
{
	const int NUM_RAND = 500;
	vector <int> sizes(NUM_RAND);
	unsigned seed = time(0);
	srand(seed);
	
	

	for (int i = 0; i < NUM_RAND; i++)
	







}

void count(int x)
{
	int holdRand;
	int max = 100;
	int min = 1;
	holdRand = (rand() % (max - min + 1)) + min;

	if (holdRand % 2 == 0)
	{
		
	}
}
using std::generate and the, newer, random 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
33
34
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
#include <random>
#include <iomanip>
#include <fstream>

constexpr auto low_score = 1;
constexpr auto high_score = 100;
constexpr auto SIZE = 20;


int main()
{
    auto seed = std::chrono::system_clock::now().time_since_epoch().count();//seed
    std::default_random_engine dre(seed);//engine
    std::uniform_int_distribution<int> di(low_score,high_score);//distribution based on low and hi scores

    std::vector<int> scores_One(SIZE);//to record the scores
    std::vector<int> scores_Two(SIZE);
    std::generate(scores_One.begin(), scores_One.end(), [&]{ return di(dre);});//generates SIZE random nos b/w low and high
    std::generate(scores_Two.begin(), scores_Two.end(), [&]{ return di(dre);});
    //http://en.cppreference.com/w/cpp/algorithm/generate

    for (const auto& elem : scores_One) std::cout << elem << " "; std::cout << "\n";
    for (const auto& elem : scores_Two) std::cout << elem << " "; std::cout << "\n";

    size_t counter{};
    for (size_t i = 0; i < SIZE; ++i)
    if ((scores_One[i]%2 == 0) && (scores_Two[i]%2 == 0)) ++counter;

    std::cout << counter << "\n";
}
I'm not sure I understand @gunnerfunner,
I haven't been taught to use #include <algorithm> or #include <chrono>
also why is #include<fstream> being used if there isn't a file being read or outputted?
why is #include<fstream> being used if there isn't a file being read or outputted?

good spot, it's a carry-over from something I was working on when I picked up your post, there's <iomanip> in there as well that's not required.
Now, to get back to your issue, if you cant use those libraries suggested, it gets a bit tricky because as I'd posted recently trying to fill 2 containers with random numbers in the same program seems to fill both with the same set of random numbers each time!
http://www.cplusplus.com/forum/beginner/212961/#msg994714
So, unless someone comes up with a neater solution, you could have one std::vector or std::list of 1000 and then split / splice the container into 500 elements each and finally run the test vis-a-vis line 31 of my earlier post (details for splicing std::list in above thread):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

// function prototype
//void count(int x);

const int NUM_RAND = 20;

int main()
{

	vector <int> sizes{};
	srand(time(NULL));
    
    for (int i = 0; i <  2 * NUM_RAND; i++)
    {

        sizes.push_back(rand()%100 + 1);
    }
    for (const auto& elem : sizes)std::cout << elem << " "; std::cout << "\n";
}
Topic archived. No new replies allowed.