Random generator

Hy I have a problem with my school project. I need a program to generate random numbers, in predefined colums and rows. The problem is that the program only generates row numbers once and not how many times you define it.

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
#include <stdio.h>      
#include <stdlib.h>     
#include <time.h>       
#include <iostream>

using namespace std;

int main ()
{
  int n, kombi, stevilo, x, y;
  
  srand (time(NULL));  //random seed

  x=0;
  y=0;
  
  printf ("Vpišite željeno količino številk: "); //you enter how many numbers you want in one row
  scanf ("%d",&stevilo);
  printf ("Vpišite število kombinacij: ");  //you enter how many colums you want
  scanf ("%d",&kombi);
  do {
	if (y<kombi) //if - to jump to new line
		{
	  	cout<<endl; //jumps to the new line
	  	y++;
		if (x<stevilo) //if - to fill the row with numbers "stevilo"
			{
				n = rand() % 10 + 1;   //generates a random number from 1-10
				cout<<n<<", ";    //output the random number
				x++;
			} 	
		}
  } while (y<kombi);
  return 0;
}
Try solving it using two-dimensional arrays. It will be easier(or at least more natural approach), and probably you should use it in this task.
Topic archived. No new replies allowed.