Ask Question
5 May, 16:47

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

+5
Answers (1)
  1. 5 May, 19:04
    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?
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