Homework 3: Console I/O
Due: Tuesday 9/27 by 1pm
Objectives
For this homework assignment you will practice writing programs that use the printf() and scanf() functions.
The Assignment
- [Adapted from Hanly&Koffman]
Write a C program that converts temperatures from degrees in Fahrenheit to the equivalent value in Celsius. Your program should prompt the user to enter the temperature in Fahrenheit, then output the temperature in Celsius. Sample runs of your program might look like:Enter temperature in Fahrenheit: 32 That is equal to 0.000000 degrees Celsius
Enter temperature in Fahrenheit: 98.6 That is equal to 37.000000 degrees Celsius
Enter temperature in Fahrenheit: 212.0 That is equal to 100.000000 degrees Celsius
Name your program hw3-1.c. Use the script command to record several sample runs of your program. (Remember to exit from script when you are done.) Then submit your program and typescript file using
submit cs104_chang hw03 hw3-1.c submit cs104_chang hw03 typescript
- [Adapted from Hanly&Koffman]
It is the day before final exams and you want to compute how well you have to do on the final exam to get the grade you want.Write a program to calculate this magic number for you. A sample run of your program should look like:
This program calculates what you need to get on your final exam. Enter desired letter grade: B Enter cutoff for desired letter grade: 79.5 Enter current average: 77.6 Enter weight of final exam: 25 Number of points obtained: 58.200000 Number of additional points needed: 21.300000 You need to get 85.200000 percent on your final exam in order to get a grade of B.
Notes:
- The points obtained is 58.2 in this example because the final exam is worth 25 points. That means the total points obtainable up to now (if you had 100% on everything) is 75 points. An average of 77.6% means that you currently have 75 * 0.776 = 58.2 points.
- You need 79.5 points to get a B, so you need an additional 79.5 - 58.2 = 21.3 points.
- That means you need to get 21.3/25 = 85.2% on the final.
- You can use a variable of type char to store the letter grade. For char variables, use %c in the format string for printf() and scanf().
Name your program hw3-2.c. Use the script command to record several sample runs of your program. Since you don't want to overwrite the typescript file from #1, use this form of the script command:
script -a typescript2
This will record the sample runs in a file called typescript2 instead of the default typescript. Remember to exit from the script command when you are done.
Finally, submit your program and sample runs using:
submit cs104_chang hw03 hw3-2.c submit cs104_chang hw03 typescript2
- (Extra Credit)
Write a C program that computes the number of quarters, dimes,
nickels and pennies used to make change. Your program should
minimize the number of coins given. A sample run of your program
should look like:
Enter the amount of change (in cents): 67 Change for 67 cent(s): # quarters = 2 # dimes = 1 # nickels = 1 # pennies = 2
Name your program hw3-3.c. Use the script command to record several sample runs of your program in a file named typescript3. (See instructions in Question 2 above.) Finally, submit your program and sample runs using:
submit cs104_chang hw03 hw3-3.c submit cs104_chang hw03 typescript3
Be sure to logout completely when you have finished!