Assignment #2

Due: Thursday, June 1

Objective

This assignment will involve practice with basic I/O, as well as practice with selection statements

Task

Write the following programs, each in a separate file. Filenames should be: (Note that the filenames are all lowercase)

Exercise 1

Filename: triangle.c

Write a program that does the following:

Prompt the user and let them enter three integers. Determine and print out whether these three numbers could be the lengths of the sides of a right triangle. Your output should look like mine below in the sample runs (i.e. print the numbers and the message). The numbers can be entered in any order.

Recall that a right triangle must satisfy the pythagorean theorem, so that if x and y are the legs of the triangle, and z is the hypotenuse, the following algebraic formula is true:

  x2 + y2 = z2
(Also note that "Myers' First Law of Common Sense" says that the sides of a triangle must have positive lengths! :-)
 

Sample Runs

(user input is underlined, to distinguish it from output)

Sample run 1

  Input three integers: -2 0 5

  The numbers -2, 0, and 5 CANNOT be the sides of a right trangle.

Sample run 2

  Input three integers: 3 4 5

  The numbers 3, 4, and 5 CAN be the sides of a right triangle.

Sample run 3

  Input three integers: 6 11 8

  The numbers 6, 11, and 8 CANNOT be the sides of a right triangle.


Exercise 2

Filename: credit.c

This program will obtain entry of credit card information for a single month, then will print a small summary and determine whether the credit limit has been exceeded or not. Do the following:

  1. Prompt the user, and allow them to enter the following information (in this order): The account number is an integer, but all other values are monetary values. For monetary values, use type double in this program
  2. Compute the new balance (starting balance + charges - credits), and print a summary for the account.
  3. Once the summary is printed, determine whether the new balance has put the account over the credit limit or not, and print the appropriate message.

Sample Runs

(user input is underlined, to distinguish it from output)

Sample Run 1

Enter the account number: 123
Enter the credit limit for the account: 5000.00
Enter the starting balance for this month: 3465.12
Enter the total charges for this month: 1699.34
Enter the credits for this month: 500.00

** Summary for account # 123 **

Starting balance:       $   3465.12
Monthly charges:        $   1699.34
Monthly credits:       <$    500.00>
                        -----------
New Balance:            $   4664.46

Available credit:       $    335.54

Sample Run 2

Enter the account number: 2453
Enter the credit limit for the account: 2500.00
Enter the starting balance for this month: 2005.45
Enter the total charges for this month: 1348.32
Enter the credits for this month: 747.43

** Summary for account # 2453 **

Starting balance:       $   2005.45
Monthly charges:        $   1348.32
Monthly credits:       <$    747.43>
                        -----------
New Balance:            $   2606.34

Credit limit of $2500.00 exceeded by $106.34

Requirements for both programs


Submitting:

Submit only your source code files through the web submission page. As there are two of them, this will require filling out the submission page twice. Make sure to click on "Assigment 2" both times. Submit the files:

  triangle.c
  credit.c