Question
1. Lotto Numbers Here is the code to generate 6 random numbers between 1 and 50. int numbers[] = {0, 0, 0, 0, 0, 0};
1. Lotto Numbers
Here is the code to generate 6 random numbers between 1 and 50.
int numbers[] = {0, 0, 0, 0, 0, 0};
int main() {
srand(time(0));
for(int i=0; i<6 ; i++)
numbers[i] = rand() % 50 + 1;
}
We want to generate 6 distinct numbers (Lotto) using the following approach. Write the code for a new function duplicate() to return true if value is found in numbers[] array. Use duplicate() in main() to simplify the logic and ensure that we end up with 6 distinct numbers between 1 and 50 in the array.
int numbers[] = {0, 0, 0, 0, 0, 0};
bool duplicate(int value) {
for (I = 0; I < 6; i++)
{
if (num[i] == value)
return true;
}
Return false;
}
int main() {
srand(time(0));
for(int i=0; i<6 ; i++)
{
Do
{
nextnum = rand() % 50 + 1;
} while (duplicate(nextnum))
number[i] = nextnum;
}
}
I need help writing this program out, but i also need comments so i know how it works. The more detailed the better!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started