Homework 4
2010_F18/wk4/hw4.cpp
Loops With Numbers
The purpose of this homework assignment is to use a looping structures for a
menu based program, user input validation and program output. You will
write a program displaying a menu for three options: 'summation', 'fibonacci',
and 'exit'.
Summation
-Ask the user for a positive integer value and
validate that it's positive, otherwise have the user re-enter until valid.
Once validated, given the inputed value, you will calculate the
sum of all the integers from 1 to the number inputed. For example,
if the user enters 5, you will display and calculate the sum
of 1 + 2 + 3 + 4 + 5 = 15 ('+' signs included). Before you break
out of the switch statement, reset your running total back to zero.
Then, reiterate and display the menu again until the user's choice is to exit.
Fibonacci
-Ask the user for a positive integer and validate that it is positive,
otherwise have the user re-enter until valid. Once validated, given the
inputed value, you will display (calculate)
the first number inputed fibonacci numbers. For example, if the user
enters 5, display "1, 1, 2, 3, 5" ('commas' included). Break out of the
switch statement, reset your fibonacci numbers back to their starting
values. Then reiterate and display the menu again until the
user's choice is to exit.
Example Output
1. Summation
2. Fibonacci
0. Exit
-------------
Enter choice: 1 [entered]
Enter a positive number: 5 [entered]
1 + 2 + 3 + 4 + 5 = 15
1. Summation
2. Fibonacci
0. Exit
-------------
Enter choice: 2 [entered]
Enter a positive number: 5 [entered]
1, 1, 2, 3, 5
1. Summation
2. Fibonacci
0. Exit
-------------
Enter choice: 0 [entered]
Good Bye