Ask Question
5 October, 13:37

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 0 and 9. End with a newline. Ex:

5

7

Note: For this activity, using one statement may yield different output (due to the compiler calling rand () in a different order). Use two statements for this activ

+2
Answers (1)
  1. 5 October, 16:13
    0
    The C+ + code is given below with appropriate comments

    Explanation:

    //Use stdafx. h for visual studio.

    #include "stdafx. h"

    #include

    //Enable use of rand ()

    #include

    //Enable use of time ()

    #include

    using namespace std;

    int main ()

    {

    //Note that same variable cannot be defined to two

    //different type in c++

    //Thus, use either one of the two statement

    //int seedVal=0; time_t seedVal;

    //int seedVal=0;

    time_t seedVal;

    seedVal = time (0);

    srand (seedVal);

    //Use rand to generate two number by setting range

    / / between 0 and 9. Use endl for newline.

    cout << (0 + rand () % ((10 - 0) + 0)) << endl;

    cout << (0 + rand () % ((10 - 0) + 0)) << endl;

    //Use for visual studio.

    system ("pause");

    return 0;

    }
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