Homework 6 - UMBC-CMSC104/General GitHub Wiki

Loops

For this program, we're going to be modifying Homework 4 by adding loops to it.

The Assignment

Name the code for this assignment loops.c.

The way homework 4 works now, the user is able to select add, subtract, multiplication, division, or modulus, enter two numbers, see the calculation, and the program exits.

We want to ensure two things:

  • The program only exits after the user requests
  • The program allows more than two numbers to be entered for addition, subtraction, multiplication, and division. Modulus can be left as is due to the way it works.

An example of the menu:

Welcome to homework 4!
Please select an option:
1) Add two numbers
2) Subtract two numbers
3) Multiply two numbers
4) Divide two numbers 
5) Modulus two numbers
Type -1 to exit

If the user types -1 from this menu, then the program should exit.

An example of addition:

Please start entering numbers you'd like to add:
Please enter a number (0 to stop): 

The user would then enter numbers until entering 0:

Please start entering numbers you'd like to add:
Please enter a number (0 to stop): 1
Please enter a number (0 to stop): 5
Please enter a number (0 to stop): 3
Please enter a number (0 to stop): 20
Please enter a number (0 to stop): 0
The sum was 29!

This would work similarly for subtraction, multiplication, and division. It would be wise to choose the "ending" number to be 1 for multiplication/division (just due to the way multiplication/division works with 1).

Use functions where appropriate. Don't duplicate functionality!

To submit the file, type:

submit cs104_wilson hw06 loops.c