c++(cpp) Your club is in a process of creating a weekly lottery. Once a week, fi
ID: 3773758 • Letter: C
Question
c++(cpp)
Your club is in a process of creating a weekly lottery. Once a week, five distinct random integers between 1 to 40 (inclusive) are drawn. If a player guesses all of the numbers correctly, the player wins a certain amount.
Write a program that does the following:
Generates five distinct random numbers between 1 and 40 (inclusive) and stores them in an array. You need to use function for populating array of random numbers.
Sorts the array containing the lottery numbers using a function.
Prompts the player to select five distinct integers between 1 and 40 (inclusive) and stores the numbers in an array. The player can select the numbers in any order, and the array containing the numbers need not be sorted.
Determines whether the player guessed all the lottery numbers correctly. If the player guessed the lottery numbers correctly, it outputs the message ‘‘You win!’’; otherwise it outputs the message ‘‘You lose!’’ and outputs the lottery numbers.
Your program should allow a player to play the game as many times as the player wants to play. Before each play, generate a new set of lottery numbers.
Explanation / Answer
#include <random>
typedef std::uniform_real_distribution<double> distr_uni;
#define max_threads 1
using namespace std;
int main(int argc, char* argv[])
{
int reservoir_counter, accepted_tube=0;
double r;
omp_set_num_threads(max_threads);
#pragma omp parallel
{
mt19937 eng(0);
distr_uni uniform(0, 1);
#pragma omp for private(r, reservoir_counter) reduction(+:accepted_tube)
for(reservoir_counter=0; reservoir_counter<100000; reservoir_counter++)
{
r = uniform(eng);
if(r>0.5)
{
accepted_tube++;
}
}
}
cout << accepted_tube << endl;
return 0;
}
Fuzzile:
#include
int main(){
int i;
for(i=1; i<=100; i++){
switch((2+i/3-(i+2)/3)*(3+i/5-(i+4)/5)-2){
case 1: printf("Buzz "); break;
case 2: printf("Fizz "); break;
case 4: printf("FizzBuzz "); break;
default: printf("%d ",i);
for (int i = 1; i<=100; i++)
{
if ((i%3)==0 && !(i%5) == 0) {
cout << "fizz" << endl;
} else if (!(i%3)==0 && (i%5)==0) {
cout << "buzz" << endl;
} else if ((i%3==0) && (i%5)==0) {
cout << "fizzbuzz" << endl;
} else {
cout << i << endl;
}
}
}}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.