LAB 05A - myRand FUNCTION

Concepts

The focus on this assignment is on one main concept: how functions are like "mini-programs" that you can define and use.

Defining Your Own Functions

There are many ways to define your own functions. For now, we focus on the style of "defining functions above main." For example:

#include <iostream>
using namespace std;

// Returns the sum of x and y.
int Plus(int x, int y) {
    return (x + y);
}

int main() {
    int a = 2, b = 3;
    cout << Plus(4, 5) << endl;
    cout << Plus(a, b) << endl;
    return 0;
}

Notice how we defined what "Plus" is by defining the function implementation for Plus above main. Notice how, in main, we used the function Plus, passing it the necessary arguments it needs in order for it to do what it needs to do (sum two numbers and return the result). Lastly, notice how we return the result of the calculation, which you would see on the screen if the function was executed.

Instructions

In Step II of Homework 03, you used the random number generator to play Rock, Paper, Scissors against the computer. In this lab, your job is to create your own random number generator function (called MyRand) that accepts one integer parameter (called theSeed) and returns a short that is either 0, 1, or 2. The value sent to the function for theSeed should be a user entered value (e.g., if you always want the computer to choose Rock, then enter the seed that'll force a Rock value to be returned). The value returned from the function should be the random number generated (using theSeed) modulo 3. Code your solution in a new project that is called Lab05A. (Your solution to this Lab will be submitted with Homework 05.)