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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!