I cant get this code to work it searches and finds the answer, but it gets an error once you search it. Heres the assignment.
a.) Create a function called howMany that will search a two dimensional array for the the number of occurences a particular number is found within the array. Your function should return the number of occurences the number appears within the array and the cooridnates that each one is found.
Your function at the very least should take as arguments the number to search for, and the two dimensional array. You are going to need some mechanisim to return the coordinates. You could use a string, an array, or a 2D array here but I will leave that up to you. This means your function needs at least 3 arguments!
b.) Create another function that will take as arguments integer values that represent row, column coordinates. return the value at that location
c.) Write a function that will fill the array with random numbers from 1 - 10. Initially, your array should be 10 rows by 9 columns
Finally write some kind of driver to demostrate the functionality of your program. It would be nice if you used some kind of a loop and a simple menu scheme.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
void fillarray(int a[][9], int row);
void show(int a[][9], int row);
int howMany(int a[][9], int num);
int main()
{
int array[10][9];
int num, occ;
fillarray(array,10);
show(array,10);
cout << "Enter the number to search for: ";
cin >> num;
occ = howMany(array, num);
cout << "Number of occurrences; " << occ << endl;
return 0;
if ( num > 0 )
{
cout << "Number of occurrences: " << occ << endl;
}
else {
cout << "Not found " << endl;
}
}
void fillarray(int a[][9], int row)
{
srand(time(0));
for(int row = 0; row < 10; row++)
{
for(int col = 0; col < 9; col++)
{
a[row][col] = (rand() % 10) + 1;
}
}
}
void show(int a[][9], int row)
{
for(int row = 0; row < 10; row++)
{
for(int col = 0; col < 9; col++)
{
cout << a[row][col] << "\t";
}
}
}
int howMany(int a[][9], int num)
{
int count = 0;
for(int r = 0; r < 10; r++)
{
for(int c = 0; c < 9; c++)
{
if(a[r][c] == num)
{
a[9][9] = c;
count++;
cout << "row: " << r << "\t"<< " col: " << c << " contains the number " << num << endl;
}
}
}
return count;
}