Extra Credit: Sum the Command Line

Problem Description

This assignment will give you more practice with reading arguments from the command line and converting strings to another data type.

Write a program that adds up its command-line arguments, which are assumed to be integers that are each separated by a space. Your program needs to be able to handle some error conditions gracefully. If a user types a command line that does not give any arguments beyond the name of the program, your program should print a message explaining the expected format of the command line for this program.

Input & Output Format

Write a program that adds up its command-line arguments, which are assumed to be integers that are each separated by a space.

For example, if I had created a program called sum:

sum 5 1 100 15

should print to the screen something like this:

Total: 121

See your book for a hint at how to convert the command line arguments to integers.

The command line may contain any number of integers. If the user types no arguments, you should print a message indicating the expected format for the command line. If the user does not enter all integers (possibly throwing in a float by mistake), you should also give an error message.

Testing

You should test your code using a variety of valid and invalid input lines. This includes, but is not limited to command lines that have no arguments (other than the program name), a large number of integers to sum, and errors in the input such as floating point numbers instead of integers.

Grading

This assignment will be worth up to 12 points.

Acknowledgements

This programming project comes from the King textbook, Chapter 13, #5