CS 102
Assignment 7
due Thursday 3 March at 01:00 AM
Table of Contents
1 Description
Write a program that will:
- Ask the user whether to convert pounds to kilograms (1) or kilograms to pounds (0).
- If user enters an invalid choice for previous item, ask him to try again.
- Ask the user for a start amount, stop amount, and step.
- If user enters a negative numbers for the step, or if stop is smaller than start, ask him to try again.
-
Print a well-formatted conversion table. To convert pounds to
kilograms, divide by
2.2
. To convert kilograms to pounds, multiply by2.2
.
Here are a few sample runs of the program, but it should work for other numbers as well.
Convert pounds to kg (1) or kg to pounds (0)? 1 Enter start amount: 90 Enter stop amount (> 90.0): 120 Enter step (> 0): 5 POUNDS KILOGRAMS ---------- ---------- 90.0 40.9 95.0 43.2 100.0 45.5 105.0 47.7 110.0 50.0 115.0 52.3 120.0 54.5
Convert pounds to kg (1) or kg to pounds (0)? 0 Enter start amount: 90 Enter stop amount (> 90.0): 110 Enter step (> 0): 4 KILOGRAMS POUNDS ---------- ---------- 90.0 198.0 94.0 206.8 98.0 215.6 102.0 224.4 106.0 233.2 110.0 242.0
Below is an example that shows all the error messages that should be supported.
Convert pounds to kg (1) or kg to pounds (0)? 2 Try again (1 or 0): 3 Try again (1 or 0): 1 Enter start amount: 14 Enter stop amount (> 14.0): 7 Error: stop must be greater than start. Enter stop amount (> 14.0): 16 Enter step (> 0): 0 Error: step must be greater than zero. Enter step (> 0): -1 Error: step must be greater than zero. Enter step (> 0): .2 POUNDS KILOGRAMS ---------- ---------- 14.0 6.4 14.2 6.5 14.4 6.5 14.6 6.6 14.8 6.7 15.0 6.8 15.2 6.9 15.4 7.0 15.6 7.1 15.8 7.2 16.0 7.3