Ask Question
8 September, 10:46

Type a statement using srand () to seed random number generation using variable seedVal. Then type two statements using rand () to print two random integers between (and including) 0 and 9. End with a newline. Ex: #include #include / / Enables use of rand () #include / / Enables use of time () using namespace std: int main () { int seedVal = 0 / * Your solution goes here * / return 0: }

+3
Answers (1)
  1. 8 September, 11:38
    0
    Replace / * Your solution goes here * / with the following code segment

    srand (seedVal);

    cout<
    cout<
    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<
    Also, the question states that, each print statement be ended with a new line;

    So, the print statements will be

    cout<
    Alternatively, by solving (9 - 0 + 1) + 0; the statements can be written as

    cout<
    Conclusively, the complete statements is as follows;

    srand (seedVal);

    cout<
    cout<
    or

    srand (seedVal);

    cout<
    cout<
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Type a statement using srand () to seed random number generation using variable seedVal. Then type two statements using rand () to print ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers