Project 4

Due: 15 Nov

Requirements Specification

Write the C code for adding, subtracting, multiplying and dividing two integers or two floating point numbers. Use the switch statement.

Your program must do the following:

  1. Prompt the user for an option : 1 for integers, 2 for floats and 0 to quit.
  2. If the user enters anything else ask for the option again. Quit if the user enters a 0.
  3. If the user selects 1 or 2 ask for the operation to be performed : A for addition, S for subtraction, D for division, M for multiplication.
  4. Ask for two integers if the user selected option 1 or for two floats if the user selected option 2 and perform the operation.
  5. Print an error message if the user selects an invalid operation.
  6. Print out the result of the operation on the two numbers in the format shown below.
  7. Ask the user again for an option : 1 for integers, 2 for floats and 0 to quit. Continue until the user wants to quit.
Name the source code file: proj4.c

Submission

Email the source file (the .c file) as an attachment to the TA at dipesh1@umbc.edu.

The subject of the email should be "CMSC104 Section 0401 Project 4". This must be an exact match for the TA to be able to filter the mail and put your work in the correct folder! Write your name, last four digits of your social security number and your section number in the body of the email. Please follow all this instructions and make sure that you have met them before sending the email. Don't send a copy to me. You will lose points if you don't follow the instructions.

Example Output 1

In the following example, the program displays what is in Blue and the user types what is in Red.

Enter 1 for integers, 2 for floats, 0 to quit: 8
Invalid option. Try again.
Enter 1 for integers, 2 for floats, 0 to quit: 1
Enter A to add, S to subtract, D to divide and M to multiply: A
Enter integer 1: 24
Enter integer 2: 12
Answer : 24 + 12 = 36
Enter 1 for integers, 2 for floats, 0 to quit: 2
Enter A to add, S to subtract, D to divide and M to multiply: M
Enter float 1: 1.2
Enter float 2: 3.4
Answer : 1.200000 * 3.400000 = 4.080000
Enter 1 for integers, 2 for floats, 0 to quit: 0
Quitting !!

Example Output 2

In the following example, the program displays what is in Blue and the user types what is in Red.

Enter 1 for integers, 2 for floats, 0 to quit: 1
Enter A to add, S to subtract, D to divide and M to multiply: X
Enter integer 1: 24
Enter integer 2: 12
Invalid operation selected. Try again
Enter 1 for integers, 2 for floats, 0 to quit:1
Enter A to add, S to subtract, D to divide and M to multiply: A
Enter integer 1: 24
Enter integer 2: 12
Answer : 24 + 12 = 36
Enter 1 for integers, 2 for floats, 0 to quit: 0
Quitting !!
 

-- Remember the program keeps on asking for options unless the user wants to quit.
-- Also the user can alternate between asking to perform a float operation and an integer operation in any random order.
-- Make sure you use the switch statement.
 

Program Header Comment Block

Use the following comment block at the beginning of your source code:
/* 
** Filename:       proj4.c
** Name:           Your name
** SSAN:           Last four digits of your SSN   
** Date:           Date of submission
** Course:         CMSC-104 Section XXX 
** Description:    (Your psuedocode goes here.  Must be detailed)
** Notes:          (As needed, such has how to compile)
*/


You will lose points if you don't follow the instructions for the Header Comment Block.