EECS 110: INTRODUCTION TO PROGRAMMING

Programming Assignment #1

This assignment is designed to get you started in programming in C. There are 3 problems, which should be done in order. Each problem solution should be put in a separate C file in a separate project.

If you use Bloodshed's Dev-C++, use these instructions for compiling code.

If you use Microsoft's Visual Studio, use these instructions for compiling code.

In class, my demonstrations will use Dev-C++.

Problem #1: Fixing broken code

Create a new project for this assignment, e.g., PA1. Add a C file named pa1_1.c (for assignment 1, problem 1) to it. Type the following code into pa1_1.c:

#include<stdio.h> ;
int main () {
printf("Type any letter except Z or z: ")
scanf(" %c", lttr);
printf("You typed %d/n");
char next_letter; next_letter = ltr + 1;
printf("The next letter is %c."); /* print
the next letter
Return 0;
}

This is not working code. It has several kinds of errors. Furthermore, it is not written in a very readable way. Fix the program so that it compiles and runs with no errors. Then make changes to improve the readability of the program. A sample execution should go like this:

Type any letter except Z or z: g
You typed g.
The next letter is h.

Problem #2: Temperature converter

Create a new project and add a C file named pa1_2.c (for assignment 1, problem 2) to it. Write code in pa1_2.c that does the following:

  1. Asks the user to enter the temperature in degrees Fahrenheit.
  2. Reads the value.
  3. Uses the value to compute the equivalent degrees Celsius.
  4. Prints the result.

The formula for converting degrees Fahrenheit to degrees Celsius is C = (F - 32) . 5.0/9.0.

Things to think about:

Problem #3: Penny converter

Create a new project and add a C file named pa1_3.c (for assignment 1, problem 2) to it. Write code in pa1_3.c that does the following:

  1. Asks the customer how many pennies they have.
  2. Reads the value.
  3. Calculates how this could be done with fewer coins of larger denomination.
  4. Prints the result.

For example, if the customer says they have 37 pennies, then the program should say that this is equivalent to one quarter, one dime and two pennies. A sample execution of your program could look like this:

Welcome to ACE, the Automatic Coin Exchange machine.
Enter number of pennies: 37
Thank you. Your pennies are worth
1 quarter(s)
1 dime(s)
0 nickel(s)
2 pennies

Hints and tips:


Valid HTML 4.01 Strict