// Author: Keith Shomper // Date: 10/10/03 // Purpose: To demonstrate array access and modification // ** WARNING: This code has a bug #include #include using namespace std; int main() { const int SIZE = 10; string s; float smallest; // Initialize the random number generator srand(time(0)); // declare other array objects, of various initializations float a[SIZE]={4.5, 34.2, 2.0074, 29.5, 6.7, 3.3003, 29.9, 12.34, 5, 6.113}; // Arbitrarily determine which element we think is the smallest int idx = rand() % SIZE; // Print out the contents of array 'a' cout << "The array 'a' has the values: " << endl << '\t'; for (int i = 0; i < SIZE; ++i) { cout << a[i] << " "; } cout << endl << endl << "Press enter to continue .... "; getline(cin, s, '\n'); // Find the smallest element of the array smallest = idx; for (int i = 0; i < SIZE; ++i) { if (a[i] < smallest) { smallest = a[i]; } } // report the results cout << "The smallest value is " << smallest << endl; // " in position " << what?? << endl; return 0; }