/* testRandom.cpp CIS 150 6/3/2008 David Klick This program demonstrates how random integers can be generated. */ #include #include #include using std::cout; using std::cin; void cont(); int main() { int low = 10; int high = 15; int num = 0; // calculate range of numbers desired int range = high - low + 1; // seed random number generator srand(time(0)); // generate and display 10 random numbers // within desired range num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; num = rand() % range + low; cout << num << '\n'; cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); } /* Sample run: 10 11 13 13 14 15 12 11 11 14 Press enter to continue... */