CMSC 104, Fall 2012

Homework 5

Input & Output

Out: Tuesday October 16, 2012
Due: Before 11:59 PM on Monday, October 22
Note that late homeworks will NOT be accepted.

Objectives:

practice using printf() and scanf()

Assignment

Write a program that asks the user for the user's name and the user's height in inches. Your program then replies with the user's name and height in centimeters. A sample run of your program might look like this: (The user's response is in orange.)


linux3[1]% gcc -Wall height.c -o height.out

linux3[2]% ./height.out
What is your name? Lancelot
How tall are you in inches? 78
Hello, Lancelot. You are 198.120000 centimeters tall.
linux3[3]% 

Notes

  1. Please name your C program height.c

  2. You can use any of the programs we have seen in class as a starting point.

  3. Think about how many variables you might want for this program. What should their types be? int, double, ...?

  4. If you have extra time, consider the following embellishments:

    • Most people do not need to see their height with 6 digits after the decimal point (especially in centimeters). In printf(), you can use modifiers with %f to specify the precision. For example %8.3f, says to print a total of 8 characters (including the decimal point) and use 3 digits after the decimal point.

    • Play around with the precision until you have a format that looks good to you.

    • Suppose that you want to round the height to the nearest centimeter. E.g., you want to have 198.120000 reported as 198 and 198.621000 reported as 199. How can you do this?

Submitting the Program

For this assignment, you just submit your source code file, height.c (make sure you you this name). To submit your project, type the following at the Unix prompt. Note that the project name starts with uppercase 'H'. submit cs104_park Hw5 height.c To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show the file that you submitted in a format similar to the Unix 'ls' command. submitls cs104_park Hw5