Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions