Computer Science I

MC140.01

Spring 2001

Assignment 2

due Monday 29 January 2001

The goal of this assignment is to practise using integer data types, formatted input and output and arithmetic operators.

This assignment is worth 2% of your semester grade.

  1. Write a program that emulates a simple adding machine. The user will enter a fixed number of numbers and your program will add them all together and output the answer.
    1. Ask the user to enter the total number (N) of numbers that will be added.
    2. Echo the total number (N) of numbers to the screen.
    3. Ask the user to enter each number, one at a time. Echo each number, as it is entered, and also output the running total.
    4. At the end, output the total.

    Here's a sample run. The numbers in big, bold font were entered by the user. The rest was output by the computer.

    Please enter the total number of numbers that you want to add together: 3
    
    Please enter number #1: 5
    You entered 5. The total is now 5.
    
    Please enter number #1: 7
    You entered 7. The total is now 12.
    
    Please enter number #1: 8
    You entered 8. The total is now 20.
    
    The grand total is 20.
    Thanks for playing!
    

  2. Submit the assignment in the usual way (i.e., follow the submission instructions from assignment #1).