ifs

 

 

Exercise 1 --- Discount Prices

During a special sale at a store, a 10% discount is taken on purchases over $10.00. Write a program that asks for the amount of purchases, then calculates the discounted price. The purchase amount will be input in cents (as an integer):

Enter amount of purchases:
2000
Discounted price: 1800

Use integer arithmetic throughout the program.

 


Exercise 2 --- Order Checker

Bob's Discount Bolts charges the following prices:

Write a program that asks the user for the number of bolts, nuts, and washers in their purchase and then calculates and prints out the total. As an added feature, the program checks the order. It is usually a mistake if there are more bolts than nuts. In this case the program writes out "Check the Order." Otherwise the program writes out "Order is OK." In either case the total price is written out.

 

Number of bolts:
12
Number of nuts:
8
Number of washers:
24

Check the Order

Total cost: 108

Use constants for the unit cost of each item. In other words, declare something like final int boltPrice = 5; and so on in your program.

 

 


Exercise 3 --- Last Chance Gas

Al's Last Chance Gas station sits on route 190 on the edge of Death Valley. There is no other gas station for 200 miles. You are to write a program to help drivers decide if they need gas. The program asks for:

The program then writes out "Get Gas" or "Safe to Proceed" depending on if the car can cross the 200 miles with the gas remaining in the tank.

 

Tank capacity:
12
Gage reading:
50
Miles per gallon:
30
Get Gas!

Exercise 4 --- Pie Eating Contest

At the State Fair Pie Eating Contest all contestants in the heavyweight division must weigh within 30 pounds of 250 pounds. Write a program that asks for a contestant's weight and then says if the contestant is allowed in the contest.

Exercise 5 --- Tire Pressure

The front tires of a car should both have the same pressure. Also, the rear tires of a car should both have the same pressure (but not neccessarily the same pressure as the front tires.) Write a program that reads in the pressure of the four tires and writes a message that says if the inflation is OK or not.

Input right front pressure
38
Input left front pressure
38
Input right rear pressure
42
Input left rear pressure
42

Inflation is OK