// Author: Keith Shomper // Date: 10/10/03 // Purpose: To demonstrate re-directed I/O, error output, variable scope, // and arrays #include #include #include using namespace std; int main() { // the number of array elements, the smallest and the largest values int n, min, max; // seed the random number generator srand(time(0)); // Prompt the user for the number of random numbers to generate cerr << "How many random numbers do you want to generate? "; cin >> n; // Prompt the user for the range of the randome numbers to generate cerr << "Within what range would you like the numbers (e.g., min, max)? "; cin >> min >> max; // The collection of statements within '{' and '}' are called blocks // objects "live" from the moment of declaration until the end of the // enclosing block { // The size of the array const int SIZE = n; // declare an int array of the given size int a[SIZE]; // print out the size of the array cout << SIZE << endl; // assign random values of the given range to the array and print them // out for (int i = 0; i < SIZE; ++i) { a[i] = rand() % (max-min+1) + min; cout << a[i] << endl; } } return 0; }