Homework Four

Write a program that will count from any number to any other number.

  1. Prompt the user for two numbers. Ther order of the numbers should not matter.
  2. Determine which number is the "high" number and which number is the "low" number.
  3. Use a call-by-reference function swap to swap the values if needed.
  4. Allow the user to select a value to count by (for example, counting by 2.)
  5. Use the case statement to implement a menu of choices.
  6. Count "forwards" or "backwards" using for loops.
  7. Allow the user to change the low, high, and counting values.
  8. Don't forget to use separate functions for each task!

Here's a sample run. The user's input is shown in BOLD.

Welcome to the counting program.
Please enter a high and low number: 32 23
What would you like to count by? 1

Would you like to:
1. count forwards from 23 up to 32
2. count backwards from 32 down to 23
3. enter new high and low number
4. enter a new "count by" number
5. quit
> 1
Counting forwards from 23 up to 32:
23 24 25 26 27 28 29 30 31 32

Would you like to:
1. count forwards from 23 up to 32
2. count backwards from 32 down to 23
3. enter new high and low number
4. enter a new "count by" number
5. quit
> 4
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 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 new high and low number
4. enter a new "count by" number
5. quit
> 3
Please enter a high and low number: 1 10

Would you like to:
1. count forwards from 1 up to 10
2. count backwards from 10 down to 1
3. enter new high and low number
4. enter a new "count by" number
5. quit
> 1
Counting forwards from 1 up to 10:
1 3 5 7 9

Would you like to:
1. count forwards from 1 up to 10
2. count backwards from 10 down to 1
3. enter new high and low number
4. enter a new "count by" number
5. quit
> 5
Goodbye!