C++ programming Write a program that simulates a lottery. The program should hav
ID: 3761178 • Letter: C
Question
C++ programming
Write a program that simulates a lottery. The program should have an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element in the array. The user should enter five digits which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that match. For example, the following shows the lottery array and the user array with sample numbers stored in each. There are two matching digits (array elements 2 and 4).
Lottery
7 4 9 1 3
User
4 2 9 7 3
The program should display o The random numbers stored in the lottery array and the values stored in user array like above. o Number of matching digits along with the array index and the value. Eg: Array element 2 (value: 9) matches Array element 4 (value: 3) matches There are in total 2 matching digits o If all the digits match, display a message proclaiming the user as a grand prize winner.
Complete assignment question can be found at the following address, problem number 3.
http://students.cse.tamu.edu/jdass/coursematerials/assignments/Assignment_04.pdf
Explanation / Answer
#include <iostream>
int main()
{
int WinningDigits[5];
int Player[5];
int SameValue[5];
int length;
int counter = 0;
for(int j = 0; j<5;++j) //fill up the Winning Digits
WinningDigits[i];
for(int i = 0; i<5;++i) //randomly generate numbers in the Player
Player[i] = rand()%10 ; //generate numbers between 0 and 9
cout<<"DISPLAY RESULT:"<<end;
cout<<=============================================<<endl;
for(int d = 0;d<5;++d)
{
cout<<"the elements of the WinningDigits are:"<<WinningDigits[d]<<endl;
cout<<"the elements entered by player are:"<<Player[d]<<endl;
If(Player[d]==WinningDigits[d])
{
cout<<"the number"<<player[d]<<"is correct"<<endl;
SameVal[counter] = player[d];
counter++;
}
}
for(int u = 0;u<counter; ++u)
cout<<SameVal[u]<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.