Assignment F

Primary focus on chapter 5 Loops and Files

For each problem:

Problem F1

Write a do while loop to require the user to enter two integers; the second integer must be equal to, or larger than, the first integer. Both integers must be at least 1 and not larger than 20. If they do not enter correct integers, give them error messages and make them do it again until they are correct.

After the acceptable integers have been entered, use a for loop to print a table of integers and their square roots for all integers from the first integer specified by the user to the last integer specified by the user, inclusive. Align the table and print 4 decimal positions

A sample table follows, for integers 7 to 9:

INTEGER  SQUARE ROOT
      7       2.6458
      8       2.8284
      9       3.0000
  

Test the program twice:
First test, first enter: first integer = 2, second integer = 0
and after that is rejected: first integer = 2, second integer = 4

Second test, first enter: first integer = 21, second integer = 5
and after that is rejected: first integer = 5, second integer = 5

Problem F2

Read from the user the maximum number of rolls of toilet paper that may be ordered. Require the maximum number of rools that may be ordered to be an integer from 1 to 10, inclusive. If the user enters a number that is out of range, make them try again until they enter an acceptable number.

Similarly make the user enter the price of one roll of toilet paper as a decimal number of dollars and cents from ten cents(0.10) to three dollars(3.00) inclusive.

Print a table showing the number of rolls in the table for all number of rolls from 1 to the maximum number that the user specified. Each row in the table shows the number of rolls and the price for that number of rolls.

Example:

User enters maximum number of rolls as 48; make them try again.
User enters maximum number of rolls as 4; that is acceptable.
User enters the price per roll as 14.10; make them try again.
User enters the price per roll as -2.70; make them try again.
User enters the price per roll as 0.10; which is acceptable.

Print:

Rolls  Price
1      0.10
2      0.20
3      0.30
4      0.40