Struggling with arrays and functions!

I have a homework assignment that I am struggling with I think I am struggling with the instructions rather than the code but I need some help our instructions are as follows:

Write a complete program that has a main() function and the two functions of programming challenge 3 (I will include the code I already have correct at the bottom.) Your main function will have a loop that prompts for and reads data from the keyboard into two arrays. After the loop, your main function will call the testPIN function (included at the bottom) passing the two arrays and a count of the number of pairs that were read.

tesPIN function will return true if there were some matches and 0 otherwise. The testPIN function will call countMatches function (included at the bottom) passing the two arrays and the count of the pairs that were read. It will receive back the number of matches from the countMatches function.

The countMatches function will loop through the two arrays comparing every pair of corresponding numbers up to the count of numbers entered on the keyboard. Here corresponding means array elements subscripted by the same index. The count of matches will be increased by 1 every time the pairs are equal. After the loop, the count of matches will be returned to testPIN function.

The Code

#include <iostream>
using namespace std;

bool testPIN ( int [], int[], int);
int countMatches (int[], int[], int);

int main ()
{
// Here is where I'm lost.


This is the testPIN function:
bool testPIN (int custPIN[], int databasePIN[], int size)
{
if (countMatches (custPIN, databasePIN, size) == size)
return true;
else
return false;
}

This is the countMatches function:
int countMatches (int custPIN[], databasePIN [], int size)
{
int countMatches = 0
for (int index = 0; index < size; index++)
{
if (custPIN[index] == databasePIN[index])
countMatches++;
}
return countMatches;
}
These functions can be written simpler

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool testPIN( const int custPIN[], const int databasePIN[], int size )
{
   return ( countMatches( custPIN, databasePIN, size ) );
}

int countMatches( const int custPIN[], const int databasePIN[], int size )
{
   int countMatches = 0;

   for ( int index = 0; index < size; index++ )
   {
      countMatches += custPIN[index] == databasePIN[index];
   }
   
   return countMatches; 
}
Last edited on
Topic archived. No new replies allowed.