Ask Question
3 April, 02:36

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. 3 April, 05:47
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers