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

Write a program that simulates a lottery with C#. The program should have array

ID: 3828513 • Letter: W

Question

Write a program that simulates a lottery with C#. The program should have array of 6 integers named winning, with a randomly generated number in the range of 1 through 9 for each element in the array. The program should ask user to enter 6 numbers and store them in another integer array named player. The program then compares the numbers in 2 arrays to find out how many numbers match. If the two numbers are on the same position in both arrays, it is a match. (This is using parallel array concept to compare two arrays.) The program output should display the winning numbers, player’s numbers, and how many numbers matched. For instance, if your winning numbers are 3,5,9,1,4,7 and your player’s numbers are 2,5, 7,1, 9,8, then you have two matches (5 and 1). 5 is on the second position and 1 is on the fourth position in both arrays. Input Validation: Do not accept player’s number out of range of 1-9.

Explanation / Answer

Write a program that simulates a lottery :-

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

int main()
{
const int size = 6;
int wDigits[size];
int players[size];
int count1=0;
ifstream datafile;

datafile.open("player.dat");

for(int i=0; i<size; i++)
{
wDigits[i]=rand()%10;
datafile >> players[i];
if (wDigits[i]==players[i])
count1++;
}
/*
for(int i=0; i<size; i++)
{
wDigits[i]=rand()%10;
cout << "Enter number " << i+1 << " ";
cin >> players[i];

if (wDigits[i]==players[i])
count1++;
}
*/
cout << "WDigits: ";
for(int i=0; i<size; i++)
cout << wDigits[i] << " ";

cout << " Players: ";
for(int i=0; i<size; i++)
cout << players[i] << " ";

cout << " There are " << count1 << " matching elements ";
for(int i=0; i<size; i++)
if(wDigits[i]==players[i])
cout << i+1 << " ";
cout << " ";
}

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