Assignment H


Chapter 6 project 54

Hint: Use a loop to repeat the menu and pattern until the user selects 5.

Use exactly the test data provided in the book. Note that option 6 is invalid and the program does not ask for a size again. Size 10 is invalid, and size 7 is used when the program requests a corrected size.


Problem H1

Write a program which will has two functions, the main function and the input function.

The input function asks the user to enter an integer from 10 to 20, inclusive.

In the input function:

1) If the user enters a number that is out of the required range, the number is NOT returned to the main function; instead it loops to ask the user to enter a correct number.

2) If the user enters a number in the required range, the number is returned to the main function.

3) If the user enters End Of File, the input function returns a negative one to the main function.

When the main function receives -1 from the input function, it prints a completion message and the program ends.

When the main function receives any other number, the main function prints it, and calls the input function again.

The input function does NOT print anything.

Hints:

You might use a do…while loop in the main function, that runs as long as -1 is not returned.

You might use a do…while loop in the input function, that loops as long as the user enters a number that is out of the required range.

Only code one return from each function.

Test data:

use each of the following values:

10   11   20   5   21   9   -1   18

Make sure your program does not confuse the datum -1 with

EOF, which is also -1

The main function should print   10   11   20   18   and a run completed message.