C Activity
Temperature Conversion Chart


This is a short C programming exercise that will introduce you to some core C programming constructs: comments, variable declaration, arithmetic expressions, loops and formatted output. Reference the introductory slides shown in class and/or the C resources included on the course website.


Part 1

Write a C program that produces a chart of temperature conversions from Fahrenheit to Celsius. Your program should output the Celsius conversion of  Fahrenheit temperatures in the range of  0-300 degrees F in increments of 20 degrees. The output should look exactly like this:

    0        -17
    20       -6
    40       4
    60       15
     .       .
 < other values>
     .       .
    280      137
    300      148

Use the formula of  C = (5/9)( F -32 ) to perform the conversion. Note that all arithmetic is to be done using integer variables. In C, the division of two integer numbers truncates the fractional remainder.

  1. Name your C program chart1.c in a directory named TempConvert
  2. Create an ActivityJournal.txt. First estimate the time you will need to complete the program and complete your plan. Then fill in all remaining sections as you work on the activity.
  3. Keep track of the number of times you attempt to compile your program and generate a compiler error of any type. Note that number in the ActivityJournal.txt along with the actual time to complete the program. 
  4. On nitron, compile your program using the GNU C Compiler (gcc) as follows:
        gcc -o chart1 chart1.c
  5. When you get a clean compile, the executable program will be named chart1 (that's what the -o (output) option is for). To test your program, execute the following command:
  6. The command runs your program; the ./ forces the command language interpreter (bash, or the Bourne-Again Shell) to look in the current directory rather than the directories for standard system commands.
  7. Submit your source file chart1.c and ActivityJournal.txt in a directory named TempConvert to your Git pushbox.
  8. Complete this Part before beginning Part 2.

Part 2

First estimate your completion time in the Activity Journal and then complete the Plan. Copy chart1.c to a new file called chart2.c. In this new file perfom the conversion calculation using floating point variables. The output should look exactly like this (note the change in justification from chart1.c):

     0      -17.8
    20       -6.7
    40        4.4


Submit your source file chart2.c and updated ActivityJournal.txt in a directory named TempConvert to your Git pushbox.

Grading Criteria

To receive full credit for this activity you do the following:

  1. Submit your work in a correctly named directory. This must be one of the top level directories in your repository.
  2. All three files chart1.c, chart2.c, and ActivityJournal.txt must have exactly these filenames.
  3. The program must compile without any warnings.
  4. The output must match the expected output including the exact formatting.
  5. Good software style including consistent indentation and appropriate variable names.
  6. Completed Activity Journal for both parts including estimates, plans, actual times, and observations.