Here is the code I have to compare two arrays, one that is already set and one that a user inputs data into, the problem I get is that when I try to run it I get the following error:
Error 2 error C2664: 'arrayComp' : cannot convert parameter 2 from 'int' to 'int []' c:\users\jainish\documents\visual studio 2008\projects\team programming 2\team programming 2\team programming 2.cpp 18

Here is the code I have so far:

#include <cstdlib>
#include <iostream>
using namespace std;

bool arrayComp(int firstArr[], int secondArr[], int size);
void pinEnter(int secondArr[], int size);

bool arrayEqual = true;

int main()
{
	const int size = 7;
	int firstArr[7] = {3,6,8,4,5,8,7};
	int secondArr;

	pinEnter(secondArr, size);

	bool equal = arrayComp(firstArr, secondArr, size);

	system("PAUSE");
	return EXIT_SUCCESS;
}

bool arrayComp(int firstArr[], int secondArr[], int size)
{
	for(int i = 0; i < size; i++)
	{
		if(firstArr[i] != secondArr[i])
		{
			arrayEqual = false;
			break;
			cout << "You have entered a wrong PIN!";
		}
		return arrayEqual;
		cout << "Welcome to The National Commerce Bank!";
	}
}

void pinEnter(int secondArr[], int size)
{
	for(int i = 0; i < size; i++)
	{
		cout << "Enter Your PIN: ";
		cin >> secondArr[i];
	}
}

Recommended Answers

All 5 Replies

You aren't declaring secondArr as an array.

You aren't declaring secondArr as an array.

Thank you, that solved the problem.:)

Edit: Just a little new problem, how can I set it so that it not only compares the array size, but also the data within the the array? As you can see it's trying to match a PIN entered to one set.

bool arrayComp(int firstArr[], int secondArr[], int size)
{
	for(int i = 0; i < size; i++)
	{
		if(firstArr[i] != secondArr[i])
		{
			arrayEqual = false;
			break;
			cout << "You have entered a wrong PIN!";
		}
		return arrayEqual;
		cout << "Welcome to The National Commerce Bank!";
	}
}

One, you never initialize arrayEqual to true. Don't assume the compiler will do it for you. Two, make sure you are going through the loop for every array index.

Does this line ever display?

cout << "Welcome to The National Commerce Bank!";

Thank you, that solved the problem.:)

Edit: Just a little new problem, how can I set it so that it not only compares the array size, but also the data within the the array? As you can see it's trying to match a PIN entered to one set.

NVM.

bool arrayComp(int firstArr[], int secondArr[], int size)
{
	for(int i = 0; i < size; i++)
	{
		if(firstArr[i] != secondArr[i])
		{
			arrayEqual = false;
			break;
			cout << "You have entered a wrong PIN!";
		}
		return arrayEqual;
		cout << "Welcome to The National Commerce Bank!";
	}
}

One, you never initialize arrayEqual to true. Don't assume the compiler will do it for you. Two, make sure you are going through the loop for every array index.

Does this line ever display?

cout << "Welcome to The National Commerce Bank!";

Thank you for the reply, but I changed a few things around. I got the program working.

#include <cstdlib>
#include <iostream>
using namespace std;

bool arrayComp(int firstArr[], int secondArr[], int size);
void pinEnter(int secondArr[], int size);

bool arrayEqual = true;

int main()
{
	const int size = 7;
	int firstArr[size] = {1,2,3,4,5,6,7};
	int secondArr[size];

	pinEnter(secondArr, size);

	bool equal = arrayComp(firstArr, secondArr, size);
    if(equal == 1)
    {
             cout << "\nWelcome to The National Commerce Bank!\n\n";
             }
             else
             {
                 cout << "\nYou have entered a wrong PIN!\n\n";
                 }
    
	system("PAUSE");
	return EXIT_SUCCESS;
}

bool arrayComp(int firstArr[], int secondArr[], int size)
{
	for(int i = 0; i < size; i++)
	{
		if(firstArr[i] != secondArr[i])
		{
			arrayEqual = false;
			break;
		}
	}
	return arrayEqual;
}

void pinEnter(int secondArr[], int size)
{
	for(int i = 0; i < size; i++)
	{
		cout << "Enter Your PIN: ";
		cin >> secondArr[i];
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.