#include void showMenu(int low, int high); int getChoice(); void countForwards(int low, int high, int step); void countBackwards(int low, int high, int step); void getLowHigh(int& low, int& high); void getStep(int& step); void sort(int& low, int& high); int main() { int low, high, step; int choice; cout << "Welcome to the counting program." << endl; getLowHigh(low, high); getStep(step); do { showMenu(low, high); choice = getChoice(); switch (choice) { case 1 : countForwards(low, high, step); break; case 2 : countBackwards(low, high, step); break; case 3 : getLowHigh(low, high); break; case 4 : getStep(step); break; } } while (choice != 5); cout << "Goodbye!" << endl; } void showMenu(int low, int high) { cout << "Would you like to:" << endl; cout << "1. count forwards from " << low << " up to " << high << endl; cout << "2. count backwards from " << high << " down to " << low << endl; cout << "3. enter a new high and low number" << endl; cout << "4. enter a new \"count by\" number" << endl; cout << "5. quit" << endl; } int getChoice() { int choice; do { cout << "> "; cin >> choice; } while ((choice < 1) || (choice > 5)); return choice; } void countForwards(int low, int high, int step) { int count; cout << "Counting forwards from " << low << " up to " << high << endl; for (count = low; count <= high; count = count + step) cout << count << " "; cout << endl << endl; } void countBackwards(int low, int high, int step) { int count; cout << "Counting backwards from " << high << " down to " << low << endl; for (count = high; count >= low; count = count - step) cout << count << " "; cout << endl << endl; } void getLowHigh(int& low, int& high) { cout << "Please enter a high and low number : "; cin >> low >> high; sort(low, high); } void sort(int& low, int& high) { int temp; if (low > high) { temp = low; low = high; high = temp; } } void getStep(int& step) { do { cout << "What would you like to count by ? "; cin >> step; } while (step < 1); } /* SAMPLE RUN Welcome to the counting program. Please enter a high and low number : 32 23 What would you like to count by ? 2 Would you like to: 1. count forwards from 23 up to 32 2. count backwards from 32 down to 23 3. enter a new high and low number 4. enter a new "count by" number 5. quit > 1 Counting forwards from 23 up to 32 23 25 27 29 31 Would you like to: 1. count forwards from 23 up to 32 2. count backwards from 32 down to 23 3. enter a new high and low number 4. enter a new "count by" number 5. quit > 2 Counting backwards from 32 down to 23 32 30 28 26 24 Would you like to: 1. count forwards from 23 up to 32 2. count backwards from 32 down to 23 3. enter a new high and low number 4. enter a new "count by" number 5. quit > 3 Please enter a high and low number : 99 66 Would you like to: 1. count forwards from 66 up to 99 2. count backwards from 99 down to 66 3. enter a new high and low number 4. enter a new "count by" number 5. quit > 4 What would you like to count by ? 33 Would you like to: 1. count forwards from 66 up to 99 2. count backwards from 99 down to 66 3. enter a new high and low number 4. enter a new "count by" number 5. quit > 1 Counting forwards from 66 up to 99 66 99 Would you like to: 1. count forwards from 66 up to 99 2. count backwards from 99 down to 66 3. enter a new high and low number 4. enter a new "count by" number 5. quit > 5 Goodbye! */