CMPT 102 Assignment #2

Due February 3, 2002

Part 1: Write a program

In part 2 of assignment 1, you described an algorithm to solve quadratic equations. Write a C program that implements the algorithm. Call the program quad.c.

You should ask the user to type the coefficients after the program starts to run:

Type the coefficients, a b c:
The user should then enter something like 1 3 2.

Your program should print one of these three things (with different numbers, obviously):

There are no real roots.
There is one real root, 2.00.
There are two real roots, -1.00 and 3.00.

All of the values should be stored in variables of type double. The numbers should be printed with two decimal places.

Here are some things to keep in mind:

Part 2: Test it

You have to test your program to make sure it works. Actually, you should be testing as you write the program, but all you have to show us is the testing of the finished program.

Get your program from Part 1 working. Then,

script quad.out
./quad  (type coefficients with no roots)
./quad  (type coefficients with one root)
./quad  (type coefficients with two roots)

Part 3: Another Program

This program will implement a guessing game. The user will enter a number and then another user will try to guess it. Here is a sample run of the program:

1: userid_fruit% ./guess
Enter a number: 102
(screen clears)
Take a guess: 50
Sorry, the number was higher than that.
Take a guess: 150
Sorry, the number was lower than that.
Take a guess: 102
That's it!

Call your program guess.c . Some notes:


You have to use the Submission server to submit your work. You should submit the files quad.c, quad.out and guess.c. You can do this by typing these commands:

tar cvf a2.tar quad.c quad.out guess.c
gzip a2.tar
Then, submit the file a2.tar.gz.