|Csc 123 Programming in C|
Algorithms using simple IF statements
1. Read in a person's temperature. If the temperature is above 99.8, have the computer say "You have a fever."
2. Ask the user what day of the week it is. If the user replies "Sunday", say "Sorry, I don't compute on Sunday."
3. Input the weight of the two people riding in a small Cessna airplane. Then input the weight of their luggage. If the total weight is over 700 pounds, say:
Warning: Aircraft overloaded.
4. Read in 2 numbers. If the numbers are not equal, print the absolute value of their sum divided by the absolute value of their difference. Use the abs() function in this calculation. Note: this is an example of using an if statement for error protection. If the numbers are equal, the program would attempt to divide by 0. You cannot divide by 0 in mathematics. An attempt to divide by 0 will crash a program in most computer languages, including C++.
5. Read in two elapsed times, expressed in hours and minutes, and print the total elapsed time. Hint: First input hours1, then minutes1, then hours2, then minutes2, and add them together in an appropriate way. Be sure the resulting minutes in your answer is less than 60.
Algorithms using IF and ELSE statements.
6. Read in two numbers and output the larger number.
7. Read in two numbers, output the larger, and then output the smaller.
8. Write a division program that asks the user for a number, and then for a divisor. If the divisor equals 0 say "You can't divide by zero", otherwise give the answer of the division.
9. Read in a number and print its absolute value without using the abs() function.
10. An amusement park sells ride tickets for $1.00 each if you buy less then 10, but only charges 90 cents each if you buy 10 or more. Write a program that asks the user how may tickets she wants to purchase, then tells her the price.
11. Input an ID number, the number of hours worked, and the hourly pay rate for an employee. Compute the gross-pay for the employee, giving time and a half for any hours over 40. Output the ID number and the gross pay.
Algorithms requiring compound conditionals
12. Input a person's age and cholesterol count. If the age is over 40 and the cholesterol is over 120, print "Possible heart problems."
13. Input a pressure on a water coolant pipe. If it is above 300 pounds per square inch or below 50 pounds per square inch, say "Coolant Emergency!!".
14. Input a person's salary. If it between 0 and 4999 inclusive, say "No tax due", otherwise say, "You must file"
Multiple IF statements with mutually exclusive conditions
15. Prompt the user for a number. If the number is greater than 12 say "More than a dozen". If it is less than 12 say "Less than a dozen". If it is equal to 12 say "An even dozen.".
16. Input a letter grade from a student. If the grade is "A", say "Excellent Job". If the grade is "B", say "Good work". If the grade is "C", say "Satisfactory progress". If the Grade is "D" or "F" say "Improvement needed". Otherwise say nothing.
17. Write a children's program that inputs a letter of the alphabet, and then prints out the name of a common household object that starts with that letter. Since this is a very long program, actually write only enough to show you would be able to complete it if necessary.
18. Ask the user for a light bulb wattage. If the wattage is 40 or 60 say "acceptable for socket". If the wattage is 75 or 100 say "socket overload". If the user enters something else, just do not respond.
19. Read the length of a television program, in minutes, from the user. If the length is under 122 minutes have the computer say "Use SP mode on your VCR". If the length is between 122 and 241 minutes, inclusive, say "Use LP mode on your VCR". If the length is between 242 and 361 minutes, inclusive, say "Use SLP mode on your VCR". If the length is over 361 minutes say "Use more than one video tape".
20. Input a person's salary. Calculate and print the tax based on the following rates: If the salary is between 0 and 4999 inclusive, the rate is 0%. If the salary is between 5000 and 14999 inclusive, the rate is 3% of everything over 5000. If the salary is above 15000 the rate is $300 plus 5% of everything over 15000.
Algorithms that require nested IF's:
21. Input a number from the user. If it is positive, input a second number from the user. If the second number is positive, multiply the two numbers together and print the result.
22. Ask the user if he is registered to vote. If the user answers with a "Y", ask him if he intends to vote in the next election. If he answers "Y" again, say "You are a good citizen."
23. Input an angle representing a partial rotation of a wheel. If it is not zero, input the number of times the wheel should do the partial rotation. If the number of times is not zero, output the total angle the wheel will rotate after doing the partial rotation the proper number of times.
24. Write a division program that asks the user for a divisor. If the divisor equals 0 say "You can't divide by zero" and end the program. Otherwise ask the user for the number to be divided and give the answer of the division.
25. Prompt the user for the length of a rectangle, and input the length. If the length is negative, say that a rectangle cannot have a negative side and stop. Otherwise, prompt the user for the width of the rectangle. If the width is negative, say that a rectangle cannot have a negative side and stop. If the width is not negative, print "The area of the rectangle is " and then print the area.
26. Write a program for OTB that asks for the amount of the bet. If the amount is greater than $2.00, say "Bet accepted, please enter the horse's number" and input the horse's number. If the horse's number is less than or equal to 8, say "You have bet ", then say the amount, then say "on horse number ", then say the horse's number. If the horse's number is greater than 8 say "Only 8 horses run in this race."
27. Input a person's age and cholesterol count. If the age is over 40 and the cholesterol is over 120, print "Possible heart problems." Otherwise, if the cholesterol is over 120, print "You should reduce your cholesterol." Otherwise print "Your cholesterol count is fine." Make sure your program prints exactly one message each time it is run.
Programs that can use descending nested greater-thans, or ascending nested less-thans. These programs can also be done with multiple IF's with compound conditionals.
28. Ask the user's age. If the user is over 60, say "That's the cat's pajamas.", otherwise if the user is over 30, say "Cool, man.", otherwise say "Radical!".
29. Input the measured length of a fish. If the length is less than 10 centimeters, print "Cat Food". Otherwise, if the length is less 20 centimeters, print "Fish Cakes". If neither previous statement is true, and the length is less than 30 centimeters, print "Super Market Quality". If none of the above are true, print "Restaurant Quality".
30. Input a number which can also have a fractional part. In other words, input a real number. If the number is less than 0, say "Out of range.". Otherwise, if the number is less than 1 print its square. Otherwise print the square of its reciprocal.
Complex algorithms with different possible good solutions.
31. Read in 3 numbers and output the largest number.
32. Read in 4 numbers and output the largest number. Note: this algorithm can be an extension of 31.
33. Get the length of 3 sides of a triangle from the user, who is allowed to enter the lengths in any order. Tell the user if it is a right triangle. (Note: If it is a right triangle, the square of the longest side will be the sum of the squares of the other two sides.)
34. Input 4 numbers and print them in ascending order.
|Back to Csc 123 Programming in C|
|Scott Badman Office: B132 Phone: 353-2250 email@example.com|
Parkland College, 2400 W. Bradley Avenue, Champaign, IL 61821