4 - Chapter 4 - Making Decisions
4 - Chapter 4 - Making Decisions
1. Minimum/Maximum
Write a program that asks the user to enter two numbers. The program should use the conditional
operator to determine which number is the smaller and which is the larger.
Input Validation: Do not accept a number less than 1 or greater than 10.
3. Areas of Rectangles
The area of a rectangle is the rectangle’s length times its width. Write a program that asks for the length
and width of two rectangles. The program should tell the user which rectangle has the greater area, or if
the areas are the same.
5. Software Sales
A software company sells a package that retails for $99. Quantity discounts are given according to the
following table.
Quantity Discount
10-19 20%
20-49 30%
50-99 40%
100 or more 50%
Write a program that asks for the number of units sold and computes the total cost of the purchase.
The bank also charges an extra $15 if the balance of the account falls below $400 (before any check fees
are applied). Write a program that asks for the beginning balance and the number of checks written.
Compute and display the bank’s service fees for the month.
Input Validation: Do not accept a negative value for the number of checks written. If a negative value is
given for the beginning balance, display an urgent message indicating the account is overdrawn.
Input Validation: Make sure the number of calories and fat grams are not less than 0. Also, the number of
calories from fat cannot be greater than the total number of calories. If that happens, display an error
message indicating that either the calories or fat grams were incorrectly entered.
Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter your choice (1-4):
If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the
following formula:
𝑎𝑟𝑒𝑎 = 𝜋𝑟 1
Use 3.14159 for 𝜋 and the radius of the circle for r. If the user enters 2, the program should ask for the
length and width of the rectangle and then display the rectangle’s area. Use the following formula: