Question
Problem 2 Write a program that calculates and displays the sum of the integers from 1 to a given number. The user inputs an integer
Problem 2 Write a program that calculates and displays the sum of the integers from 1 to a given number. The user inputs an integer number of 2 or more. The program should calculate and display the sum of all of the integers from 1 to this number. (For example, if you input 4 as the number, the program should calculate the sum: 1 + 2 + 3 + 4 and display the answer as 10.) Use a loop to validate the input, i.e. make sure that the number input is 2 or greater before proceeding with the calculation. YOU MUST USE AN ACCUMULATOR.
Sample output (TEST CASE 1):
Enter a positive integer: -4 Must be 2 or more, re-enter: 1 Must be 2 or more, re-enter: 4 The sum of the integers from 1 to 4 is 10
Test Case 2: 22
Test Case 3: 50
Problem 3: Write a program to see how your money grows in an investment account. You will enter the initial amount deposited, the interest rate, and the number of years the money will remain in the account. Assume no withdrawls are made during this time period. Calculate and display the balance at the end of each year based on the interest rate. Also display the total amount of interest earned. Use loops to validate that the deposit amount, interest rate, and number of years is greater than 0. YOU MUST USE AN ACCUMULATOR.
Sample Output (Test Case 1)
What is initial deposit? -1000 Invalid, must be greater than 0. Re-enter: 1000 What is annual interest rate (as percent)? 0 Invalid, must be greater than 0. Re-enter: 10 How many years on deposit? -3 Invalid, must be greater than 0. Re-enter: 3 Let's see how your money grows! Year Balance 1 1100.00 2 1210.00 3 1331.00 Total interest earned in 3 years is $ 331.00
Test case 2: $4900.50 deposited for 10 years at 7% interest
Test case 3: $10000 deposited for 20 years at 5.5% interest
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started