### Incrementing variable

I know my title is vague, but I would appreciate it if someone could help me figure out how to keep the i variable from incrementing when none of the elements match. For instance, if I were to input 0 0 0 0 0 for the 5 digits, Digits matched should say 0. And, if I were to input 3 0 0 0 0, Digits matched should say 1. Please help.
#include <iostream>
#include <iomanip>
using namespace std;

const int SIZE = 5;

void getPlayerDigits();
void compareDigits(int[], int[], int);
void displayDigits(int, int[], int[], int);

int main()
{
getPlayerDigits();
system("pause");
}

void getPlayerDigits()
{
int winningDigits[] = {3, 6, 9, 7, 1},
player[SIZE],
index = 0;

cout << "Enter 5 digits (add a space between each digit): ";
for (int index = 0; index < SIZE; index++)
cin >> player[index];

while(player[index] < 0 || player[index] > 9)
{
cout << "\nDo not enter a number less than 0 or greater than 9."
<< "\nRe-enter 5 digits: ";
for (int index = 0; index < SIZE; index++)
cin >> player[index];
}

compareDigits(winningDigits, player, SIZE);
}

void compareDigits(int wD[], int p[], int SIZE)
{
bool elementsEqual = true;
int index = 0,
i = 0;

while(elementsEqual && index < SIZE)
{
if (wD[index] != p[index])
elementsEqual = false;
++i;
index++;
}

if (elementsEqual)
cout << "\nCongradulations! You won the \$300,000,000 jackpot!\n";
else
displayDigits(SIZE, wD, p, i);
}

void displayDigits(int SIZE, int wD[], int p[], int i)
{
cout << "\nWinning digits: ";
for (int index = 0; index < SIZE; index++)
cout << wD[index] << " ";

cout << "\nYour digits:" << setw(5);
for (int index = 0; index < SIZE; index++)
cout << p[index] << " ";

cout << "\n\nDigits matched: " << i
<< "\nThank you for playing. " << "\n" << endl;
}
Topic archived. No new replies allowed.