Search User Input Number In Array Filled With Random Numbers Help!

I need to create A program That makes a 12x10 Array Grid Filled With Random Numbers From 0-99.

Then I need To Allow The User To Input A Number Between 0-99 And Then The program will then search through the array and count how many of the users number there is inside the array.

I need Help With The Last part As I Do Not Know How To Start It.. Please Help!

Code:

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
//Assignment 20 Program 3
#include <iostream>
using namespace std;
int main()

{
    int input;
    int number;
    int row=0;
    int col=0;
    int Array [12][10];
    srand(time(NULL));
    
//PrintArray

    for(row=0;row<12; row++)
    {          
        for(col=0;col<10; col++)
        {        
        {       
            Array[row][col]= rand() % (99-0) + 0;
        }
            cout << Array[row][col] << "\t";
        }     
        cout << ""<<endl<<endl;               
    }
    
		
cout << "--------------------------------------------------------------------------------"<< endl << endl;

	cout << "Enter Number Between 0-99 To Search In The Array: ";
	cin >> input;
    cout << "" << endl;

//Search Array With Input

    
First, you need to change
 
Array[row][col] = rand() % (99 - 0) + 0;


to
 
Array[row][col] = rand() % (100 - 0) + 0;


The way you had it would have generated a number between 0-98, the code I pasted generates from 0-99.


After that here are the changes I made to your code. Let me know what you don't understand and i'll try to clarify.

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
55

//Assignment 20 Program 3
#include <iostream>
#include <time.h> //included for srand(time(NULL))
using namespace std;
int main()

{
	int input;
	int number;
	int row = 0;
	int col = 0;
	int Array[12][10];
	srand(time(NULL));

	//PrintArray

	for (row = 0; row < 12; row++)
	{
		for (col = 0; col < 10; col++)
		{
			{
				Array[row][col] = rand() % (100 - 0) + 0;
			}
			cout << Array[row][col] << "\t";
		}
		cout << "" << endl << endl;
	}


	cout << "--------------------------------------------------------------------------------" << endl << endl;

	cout << "Enter Number Between 0-99 To Search In The Array: ";
	cin >> input;
	cout << "" << endl;

	//Search Array With Input
	int Number_Of_Occurrences = 0; //Initialize number of occurrences for your # to be 0
	for (int row = 0; row < 12; row++)
	{
		for (int column = 0; column < 10; column++)
		{
			if (Array[row][column] == input) //If the guessed number matches the  cell being compared
			{
				Number_Of_Occurrences += 1; //Increment number of occurences by 1
			}
		}
	}

	cout << "Number of Occurrences: " << Number_Of_Occurrences << endl;



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