Okay heres the background on the code. I've written a code that prints a 10x10 array or random numbers. Then prompts the user to pick a number. After user picks a number, the program then tells user the number of times number was found in the array and supossed to give the location of that number.. Everything in the code worked up until my printLocations function.. Meaning that program would print the array take input, and tell user howmany times found, but not returning the location. Here is the code below, can you tell me how i can fix the printLocations function, and 2nd am i calling it correctly in main:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
void fillArray(int ar[][10], int size);
void printArray(int ar[][10], int size);
void printLocations(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];
//int a;
fillArray(ar, 10);
printArray(ar,10);
printLocations(ar,10);
int count;
int row;
int col;
cout<<" Input a number " <<endl;
cin >> count;
cout<< count << " was found "<< countNum(ar,10,count)<< " times "<<endl;
cout << count <<" is located at row: "<< row << " col: "<<col;
cout << endl;
return 0;
}
void fillArray(int ar[][10], int size)//fills the array with random numbers in 10 rows and colums
{
for(int row = 0; row < size; row++)
{
for (int col = 0; col < 10; col++)
{
ar[row][col] = rand() % 10;
}
}
}
void printArray(int ar[][10], int size)//prints the array neatly
{
for(int row = 0; row < size; row++)
{
for (int col = 0; col < 10; col++)
{
cout <<ar[row][col]<< "\t";
}
cout<<endl;
}
}
void printLocations(int ar[][10], int size)
{
int count = 0;
int find;
for(int row = 0; row < size; row++)
{
for (int col = 0; col < 10; col++)
{
if (ar[row][col]== find)
printLocations ar[row][col];
}
}
}
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++)
{
if (a[row][col]== find)
count++;
//if (a[row][col]== find)
//cout<< " that number is found in col " << col << " row "<< row <<endl;
}
}
return count;
}