// Practice exercise lab 4 // In this exercise we need to randomly generate a number. // To accomplish this we need 2 additional libraries // "ctime" and "cstdlib". // srand(time(NULL)) seeds our random number with the // clock on our computer (which is why we need // ctime library). // rand() returns a very large random number // so we use modulo to get a number that falls // within our desired range. We add 1 because // N % n will always return a number 0 to (n-1) // when N is greater than n. // example: N % 100 will return a number within // a range of 0 - 99, so to get 1 - 100 we add // 1 to it. // Don't worry about fully understanding this // as you will not be tested over it. Just reference // this example when you need to generate a random // number. #include #include // for seeding rand #include // C standard library using namespace std; int main() { int random_number; // seeds rand (needed for getting random numbers) srand(time(NULL)); // randomly generate a number 1 - 100 random_number = rand() % 100 + 1; cout << "My random number is " << random_number << endl; // if the number is greater than 75 print "Over 75" // if the number is between 50-75 print "BINGO" // if the number is less than 50 print "Below 50" return 0; }