Problem Set for if-Statement Algorithms
- Given two values, x and y, develop an algorithm to display the greater value if they are not equal.
- The absolute difference of two values, x and y, is defined as the quantity (x-y) or (y-x), whichever quantity is positive. Develop an algorithm to display the absolute difference of two values.
- Workers are paid at anhourly rate of X dollars per hour, and they are paid time-and-a-half for any hours worked over 40. Develop an algorithm to calculate the pay for an hourly worker, given the number of hours worked, N.
- A company requires their salesmen to be with the company 4 years before they are eligible for promotion. Develop an algorithm that displays the message “Eligible” if an employee is eligible for promotion, and display the message “Not Eligible” if they are not.
- Develop an algorithm that displays the activity that is appropriate for a given outdoor temperature. Use the information in the following table.
Activity / Temperature
Swimming / greater than 85
Tennis / between 70 and 85
Golf / between 32 and 70
Skiing / between 10 and 32
Checkers / less than 10
- A utility company charges M dollars per month for electricity. It charges a fixed fraction, F, of a dollar for each kilowatt hour over a certain limit. Develop an algorithm that uses meter readings for the current month and the previous month to calculate an electric bill.
- A company that sells widgets pays its salespeople on commission. Each widget costs a fixed number of dollars, and the commission is 17% of the total sales the salesperson makes. If sales are over $1,200,000 a $50.00 bonus is paid, but if sales are under $500, then $25 are deducted from the commission. Develop an algorithm to determine a salespersons pay, given the number of widgets they sell.
- A rental car company rents compact cars for $25 per day, full-size cars for $30 per day, and vans for $40 per day. An additional charged is made at the rate of $6 per day if the customer requests insurance. Sales tax is 6%.
Develop an algorithm to determine the amount charged to a customer, given the type of car and the number of days it is rented, and whether or not insurance is requested. Display the rental cost, the insurance cost, and the tax as separate items.
- In the game of baseball a batting average is determined by dividing the number of hits a player gets by the number of official times he comes to bat. A hit is when the player reaches a base by hitting the ball. If the player reaches a base without hitting the ball, it is a walk and not counted as an official time at bat. Develop an algorithm to determine the batting average of a baseball player, given the number of times he comes to bat, N, the number of hits he gets, H, and the number of walks he has, W.
- Automobile insurance problem from 1214 lab
- Develop an algorithm to determine a students letter grade based on a given test score. If the score is 90 or more, the grade is ‘A’. If the score is between 80 and 89, the grade is ‘B’. If the score is between 70 and 79 the grade is ‘C’. If the score is between 60 and 69 the grade is ‘D’. If the score is less than 60 the grade is ‘D’.
- A triangle is scalene if none of its sides are equal. It is isosceles if two sides are equal, and it is equilateral is all its sides are equal. Develop an algorithm to determine the kind of triangle, given the length of its three sides.
- A traveler leaves at a given time of day (AM or PM) and arrives at his destination at a given time the next day. Develop an algorithm to determine the number of hours that elapse for such a journey.
H1214ifAlgoProbs.docPage 1 of 2