I have written a code that will post random numbers into a 10x10 row/col setup. I'm trying to edit the last function of code so that the user see's something like this:
Input a number
5
5 was found 3 times
5 is located at row 2, col 1; row 5, col 2 ; row 8, col 2
The current code does everything except output the last line... I've done some edits to the original code and below is what I got, can you help me figure out where Im going wrong please.. ??
#include <iostream>
#include <ctime>
using namespace std;
void fillArray(int ar[][10], int size);
void printArray(int ar[][10], int size);
int countNum(int ar[][10], int size, int find);
int main()
{
srand((unsigned int) time(0));
int ar[10][10];
fillArray(ar, 10);
printArray(ar,10);
int count;
cout<<" Input a number " <<endl;
cin >> count;
cout<< count << " was found "<< countNum(ar,10,count)<< " times "<<endl;
cout<< count << " is located at col " << countNum(ar,10,col)<<" row " <<countNum(ar,10,row)<<endl;
//return 0;
}
void fillArray(int ar[][10], int size)
{
for(int row = 0; row < size; row++)
{
for (int col = 0; col < 10; col++)
{
ar[row][col] = rand() % 101;
}
}
}
void printArray(int ar[][10], int size)
{
for(int row = 0; row < size; row++)
{
for (int col = 0; col < 10; col++)
{
cout <<ar[row][col]<< "\t";
}
cout<<endl;
}
}
int countNum(int a[][10], int size, int find)
{
int count = 0;
for(int row = 0; row < size; row++)
{
for(int col =0; col <10; ++col)
{
for(int row =0; row<10; ++row)
{
cout << ar[col][row]<<" ";
}
cout <<endl;
for (int col = 0; col < 10; col++)
{
if (a[row][col]== find)
count++;
}
}
return count;
}