Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have built two arrays for a lottery game. I am trying to get the two arrays to

ID: 3769264 • Letter: I

Question

I have built two arrays for a lottery game.

I am trying to get the two arrays to ouput any matches that occur if the statement is false.

Everything is working but my match out put is not outputing how many number matches there where. code to follow any help is greatly appreciated.

// lOTTERY
// 2 arrays first array winning digits second array player
// Winning digits 74913
// player digits should print and should also tell player how many digits matched

#include <iostream>

using namespace std;

void playLottery(int lottery[], int user[], int matchCounter[]); // prototype for the function

int main()
{
   int lottery[5] = {7, 4, 9, 1, 3 };
   int user[5] = { 0 };
   int matchCounter[5] = { 0 };

   playLottery(lottery, user, matchCounter); //call the playLottery function

   system("Pause");
   return 0;
}

void playLottery(int lottery[], int user[], int matchCounter[])
{
   cout << "Enter 5 lottery numbers ";
   cout << "after each number entered, " << endl;
   cout << "please press enter to continue." << endl;
   for (int i = 0; i<5; i++)
   {
       cin >> user[i];
  
   }

   for (int i = 0; i<5; i++)
   {
       for (int j = 0; j<5; j++)
       {
           if (lottery[i] == user[j])
           {
               matchCounter++; //if a match between the arrays is found, increment count by 1
           }
       }
   }

   cout << "lottery array ";
   for (int i = 0; i<5; i++)
   {
       cout << lottery[i] << " ";
   }

   cout << "user array: ";
   for (int i = 0; i<5; i++)
   {
       cout << user[i] << " ";
   }
     
   if (matchCounter += 5)
   {
       cout << "Congratulations!" << endl;
   }

   else
       cout << "You Lose, good day sir or madam. I said good day..." << endl;
       cout << "You had this many matches: " << matchCounter << endl;
}

Explanation / Answer

#include <iostream>

using namespace std;

void playLottery(int lottery[], int user[], int matchCounter[]); // prototype for the function

int main()
{
   int lottery[5] = {7, 4, 9, 1, 3 };
   int user[5] = { 0 };
   int matchCounter = 0 ;

   playLottery(lottery, user, matchCounter); //call the playLottery function

   system("Pause");
   return 0;
}

void playLottery(int lottery[], int user[], int matchCounter)
{
   cout << "Enter 5 lottery numbers ";
   cout << "after each number entered, " << endl;
   cout << "please press enter to continue." << endl;
   for (int i = 0; i<5; i++)
   {
       cin >> user[i];
  
   }

   for (int i = 0; i<5; i++)
   {
       for (int j = 0; j<5; j++)
       {
           if (lottery[i] == user[j])
           {
               matchCounter++; //if a match between the arrays is found, increment count by 1
           }
       }
   }

   cout << "lottery array ";
   for (int i = 0; i<5; i++)
   {
       cout << lottery[i] << " ";
   }

   cout << "user array: ";
   for (int i = 0; i<5; i++)
   {
       cout << user[i] << " ";
   }
     
   if (matchCounter == 5)
   {
       cout << "Congratulations!" << endl;
   }

   else
       cout << "You Lose, good day sir or madam. I said good day..." << endl;
       cout << "You had this many matches: " << matchCounter << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote