//============================================================================ // Name : increasing-numbers-v2.cpp // Author : R. W. Hasker // Version : // Description : Rewrite of increasing-numbers.cpp using functions and doubles. //============================================================================ #include using namespace std; const int MAX_SCORES = 100; // prototype // returns true iff nums[i] <= nums[i+1] for all i bool increasing(double nums[], int size); int readScores(double scores[], int); int main() { double scores[MAX_SCORES] = {0.0}; cout << "Enter up to " << MAX_SCORES << " scores: "; int num_scores = readScores(scores, MAX_SCORES); if (increasing(scores, num_scores)) cout << "Always increasing." << endl; else cout << "Decreased in at least one case."; return 0; } bool increasing(double nums[], int size) { // terminate: find i such that nums[i] > nums[i+1] or i+1>size int i = 0; while (i < size - 1 && nums[i] <= nums[i+1]) i++; return i >= size - 1; } int readScores(double scores[], int max) { double s; cin >> s; int count = 0; while (count < max && cin.good()) { scores[count] = s; ++count; cin >> s; } return count; }