### 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?
 ``12345678910111213141516171819`` ``````#include using std::vector; #define HEIGHT 5 #define WIDTH 5 int main() { vector > 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:

 ``123456789101112131415161718192021222324252627`` ``````//random numbers: #include #include #include 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.