Answer :
Answer:
Replace /* Your solution goes here */ with the following code segment
srand(seedVal);
cout<<rand()%(int)(9 - 0 + 1) + 0<<endl;
cout<<rand()%(int)(9 - 0 + 1) + 0<<endl;
Explanation:
From the code segment, the seedVal has already been declared and initialized to 0; The next step is to seed it as random number using srand.
The first line of the code segment in the Answer section "srand(seedVal); " is used to achieve that task.
Having done that, the next step is to write statements to generate the two random numbers using rand();
When generating random numbers, two things are to be noted;
- The lower bound; L
- The upper bound; U
Here, the lower bound is 0 and the upper bound is 9;
C rand() function uses the following syntax to generate random numbers
rand()%(int)(U - L + 1) + L
Where U = 9 and L = 0
Replacing U and L with there respective values; the syntax becomes
rand()%(int)(9 - 0 + 1) + 0
So, the two print statements will be written as
cout<<rand()%(int)(9 - 0 + 1) + 0;
Also, the question states that, each print statement be ended with a new line;
So, the print statements will be
cout<<rand()%(int)(9 - 0 + 1) + 0<<endl;
Alternatively, by solving (9 - 0 + 1) + 0; the statements can be written as
cout<<rand()%(int)(10)<<endl;
Conclusively, the complete statements is as follows;
srand(seedVal);
cout<<rand()%(int)(9 - 0 + 1) + 0<<endl;
cout<<rand()%(int)(9 - 0 + 1) + 0<<endl;
or
srand(seedVal);
cout<<rand()%(int)(10)<<endl;
cout<<rand()%(int)(10)<<endl;