Help me write this code

Write a C++ given 2D array of integers X[5][4]. Fill in elements by random() in interval [-12…33]. Find sum of even and sum of odd elements.
Do you want to be a programmer, or are you just trying to survive a course you would never have chosen?
salem c I want to be programmer, because I'm computer engeneer at university at ITU, but i don't know this question. Because I'm new to c++. Only 1 month :( thank for your help
Last edited on
Well you need to pick up the pace and start making an effort.

Dumping your assignment and hoping someone will give you an answer which you barely understand isn't going to set you up for your next assignment. This stuff is going to get much harder pretty soon, and then you'll be completely lost.

In particular, learning how to break a problem down into manageable steps.

You can start by putting your assignment into comments.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main ( ) {
  // given 2D array of integers X[5][4]
  // Can you do this?

  // Fill in elements by random() in interval [-12…33]. 
  // What's the problem here?
  // - writing the loops?
  // - filling with any random number?
  // - filling with random numbers in a range?

  // Find sum of even and sum of odd elements. 
  // What's the problem here?
  // - just adding numbers
  // - telling the difference between even and odd
}

Now fill in each item the best you can and keep hitting that compile and test button.

DO NOT try and finish the whole program in one edit.
Nobody writes whole programs in a single edit, so you need to learn how to approach s/w in a methodical manner.
The point of the exercise is to make many small steps of measured success along the way.

Add lots of cout << "DEBUG: i=" << i << endl; statements through the code to print variables so you can see whether the values meet your expectations.

When you actually get stuck, then post what you have achieved.
As a starter, to produce random numbers in the required range:

1
2
3
4
5
6
7
8
9
#include <random>

auto Rand {std::mt19937 {std::random_device {}()}};
auto randNo {std::uniform_int_distribution<int> {-12, 33}};
...
int main()
{
    // use randNo(Rand) to obtain the random number
}

Topic archived. No new replies allowed.