Menu

[Solved]Need Help Coding C Need Make Lottery Program Enter 5 Numbers 0 9 Program Generate 5 Rando Q37079677

I need help with coding with c++. I need to make a lotteryprogram where you enter in 5 numbers from 0-9 and the program willgenerate 5 random numbers 0-9 to represent the lottery numbers. I’malmost done, but the output isn’t exactly what I want. It worksfine, but the format should look like this:

lottery array: 7 4 9 1 3
user array: 4 2 9 7

p.s. I also need to count how many matching numbers there arefrom the user input and the lottery and need help with that aswell, because it says match is uninitialized for some reason.

I have been trying to get it done, but i am stuck. Here’s mycode:

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

void input(int user[], int raysize);
void rand(int lot[], int raysize);
void print(int lot[], int user[]);
int compare(int lot[], int user[]);
void matches(int match);

int main()
{
  
   const int raysize = 5;
   int user[5], lot[5];
   int match;
   srand(time(0));
   input(user, raysize);
   rand(lot, raysize);
   print(lot, user);
   compare(lot, user);
   matches(match);
   system(“PAUSE”);
}

void input(int user[], int raysize)
{
   for (int i = 0;i < 5;i++)
   {
       cout << “Enter in fivenumbers from 0-9” << endl;
       cin >> user[i];
   }
   int i = 0;
   while (user[i] < 0 || user[i]>9)
   {
       cout << “Error!” <<endl;
       exit(1);
   }
}

void rand(int lot[], int raysize)
{
   for (int i = 0; i < 5; i++)
   {
       lot[i] = rand() % 10;
   }

}

void print(int lot[], int user[])
{
   for (int i = 0; i < 5; i++)
   {
      
       cout << “Lottery numbers are:”<< lot[i]<< ” ” << ” your numbers are: “<< user[i] << endl;
      

   }
  
}

int compare(int lot[], int user[])
{
   int match = 0;
   for (int i = 0;i < 5;++i)
   {
       if (user[i] == lot[i])
       {
           match++;
       }
   }
   return match;

  
}

void matches(int match)
{
  
}

If possible can you try to do this question similar to thisstructure? It will help more that way.

Expert Answer


Answer to I need help with coding with c++. I need to make a lottery program where you enter in 5 numbers from 0-9 and the program… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *