C# For Technical Writers: Programming Exercises

Week 2

1. Temperature converter: Write a program that prompts the user to enter a temperature and then converts that number from degrees Fahrenheit to degrees Celcius. Here is the conversion formula:

C = (F − 32) × 59

You will get the user's input as a string. To convert the input into a number, use the following code:

double degreesF = double.Parse(input);

where "input" is the variable that holds the input string.

Hint: Also read the section "Operator Precedence" (pp 67-68) in the text book.

Note: You do not need to handle bad user input. If the user types something that is not a number, the program will crash.

2. File output: In class, we used the StreamReader object to read from a file. Here is the MSDN documentation for StreamReader: http://msdn2.microsoft.com/en-us/library/system.io.streamreader.aspx

Starting from that location in the MSDN documentation, see if you can write a program that writes text to a file.

Hint: Use the table-of-contents (TOC) frame on the left to look for other classes in the System.IO namespace. Also, you may wish to use the "Language Filter" tool near the top of the page to hide everything except C# in the documentation.

Note: Don't spend too much time on this problem. This exercise is less about programming, and more about reading programmer documentation. Can you find the right object to use? Is there any example code that shows you what to do? Is the documentation a help or a hindrance?

For bonus points, write a DateTime value to a file, instead of a string.


Main Page