C++ Matrix

Hi all, I`m very new to C++ and I have a homework from my c++ teacher.
A part of my homework is to make a 5x5 matrix and to show it on the screen.
Another part is to make a code which generates random numbers from 1 to 9.
Can someone help me with at least the first part?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <vector>
using std::vector;

#define HEIGHT 5
#define WIDTH 5

int main() {
  vector<vector<double> > Matrix;

  // Set up sizes. (HEIGHT x WIDTH)
  Matrix.resize(HEIGHT);
  for (int i = 0; i < HEIGHT; ++i)
    Matrix[i].resize(WIDTH);

  // I need something to fill the matrix with random numbers from 1 to 9


  return 0;
}
Last edited on
You already have the first part done, you just have to display it. What's confusing you here?
Random number generator:

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
//random numbers:

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main(){

        //int userInput = 0;

        srand(time(0));

        for(int couter = 1; counter < 25; counter++) { // or ++ counter
                     cout << 1+(rand()%9) << endl;

        }
        /* If you want a sentinel controlled program do this:
        cout << "Enter the amount of random numbers you would like: ";
        cin >> userInput;
        for(int counter = 1; counter <= userInput; counter++){
            cout << 1+(rand()%9) << endl;
        }*/

return 0;
}
Topic archived. No new replies allowed.