working with arrays and functions

I am working on a program that i have to create an out put of 20 lines generating 20 random numbers and on each line track what the biggest number was and how many times it occurred. so far i can only get one line and am kind of stuck.

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
42
43
44
45
46
47
48
49
50
51
52
53
54
  #include <iostream>
#include <ctime>

using namespace std;
int randNumGen(int);

int main()
{
	int randNum = 0;
	int bigCounter = 0;
	int bigNum = 1;
	int counter = 0;                    //counter to keep a count on random numbers
	cout << "1: ";
	int myArray[20];                   //array size declaration
	for (int i = 0; i < 20; i++)           //for loop to set parameters for array
	{
		myArray[i] = randNumGen(randNum);        //fills array with random number function
	}
		for (int j = 0; j < 20; j++)               //parameters for printing out the array
		{
			cout << myArray[j] << " ";                //Array outputs the random numbers
		}
	/*	for (int counter = 0; counter <= 20; counter++)   // loop to keep track of big number counter
		{
			if (randNum > bigNum)
			{
				bigNum = randNum;
				bigCounter = 0;
			}
			if (randNum == bigNum)
			{
				bigCounter++;
			}
		}
	cout << "\n\nThe largest number: " << bigNum << " was found " << bigCounter << " time(s)\n\n"; */

	system("pause");
	return 0;
}

int randNumGen(int randNum)
{
	int ranNum;               //holds random number
	static bool init = false;       //used to insure a random number "seed"

	if (!init)
	{
		srand(time(NULL));
		init = true;
	}
		randNum = (rand() % 10) + 1;          //generates random number between 1 and 10
		return (randNum);
}
the output should look like this:

1:  1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 the largest number was 10 2 times


except the numbers would be random and needs to do this for 20 lines
Topic archived. No new replies allowed.