In: Computer Science
I need assistance on this problem in Pseudocode and in C++ Program
Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by the time that baby is ready for retirement (67 years)! Don’t believe us? Check out the compound interest calculator from MoneyChimp and plug in the numbers!
To keep things simple, we’ll calculate interest in a simple way. You take the original amount (called the principle) and add back in a percentage rate of growth (called the interest rate) at the end of the year. For example, if we had $1,000 as our principle and had a 10% rate of growth, the next year we would have $1,100. The year after that, we would have $1,210 (or $1,100 plus 10% of $1,100). However, we usually add in additional money each year which, for simplicity, is included before calculating the interest.
Your task is to design (pseudocode) and implement (source) for a program that 1) reads in the principle, additional annual money, years to grow, and interest rate from the user, and 2) print out how much money they have each year. Task 3: think about when you earn the most money!
Lesson learned: whether it’s your code or your money, save early and save often…
Sample run 1:
Enter the principle: 2000
Enter the annual addition: 300
Enter the number of years to grow: 10
Enter the interest rate as a percentage: 10
Year 0: $2000
Year 1: $2530
Year 2: $3113
Year 3: $3754.3
Year 4: $4459.73
Year 5: $5235.7
Year 6: $6089.27
Year 7: $7028.2
Year 8: $8061.02
Year 9: $9197.12
Year 10: $10446.8
Sample run 2 (yeah, that’s $9.4MM):
Enter the principle: 5000
Enter the annual addition: 1000
Enter the number of years to grow: 67
Enter the interest rate as a percentage: 10
Year 0: $5000
Year 1: $6600
Year 2: $8360
Year 3: $10296
Year 4: $12425.6
Year 5: $14768.2 . .
Year 59: $4.41782e+06
Year 60: $4.86071e+06
Year 61: $5.34788e+06
Year 62: $5.88376e+06
Year 63: $6.47324e+06
Year 64: $7.12167e+06
Year 65: $7.83493e+06
Year 66: $8.61952e+06
Year 67: $9.48258e+06
This assignment is about Repetition Structures.
For Pseudocode, here are key words to use
: · DO … WHILE – A loop that will always run at least once ·
FOR … ENDFOR – A loop that runs until certain criteria is met ·
WHILE … ENDWHILE – A loop that runs only while certain criteria is met ·
FOREACH … ENDFOREACH – A loop that runs over elements in a data structure · BREAK - "break out" of the current loop (or other structure) you're in and start immediately after the loop · CONTINUE - skip over the current iteration of the loop and move on to the next one
Please find the PSEUDOCODE and C++ program below
/******************************************************************************
PSEUDOCODE:
===========
Read principle amount from user into principle
Read annual additional amount from user into annualAddition
Read number of years to grow value from user into
numberOfYears
Read interest rate as percentage from user into interestRate
set year to 0
FOR each iteration of year till numberOfYears with increment of
1
IF year is 0
set updatedAmount to principle
ELSE
Add annualAddition to updatedAmount and assign it to
updatedAmount
Calculate interestAdded by multiplying updatedAmount with
(interestRate/100)
Add interestAdded to updatedAmount and assign it to
updatedAmount
END IF
Print year and updatedAmount info
END FOR
*******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
//Defin variable to be used
double principle,annualAddition,updatedAmount,interestAdded;
float interestRate;
int numberOfYears, year;
//Read principle amount from user
cout<<endl<<"Enter the principle:";
cin>>principle;
//Read annual additional amount from user
cout<<endl<<"Enter the annual addition:";
cin>>annualAddition;
//Read number of years to grow value from user
cout<<endl<<"Enter the number of years to grow:";
cin>>numberOfYears;
//read interest rate from user
cout<<endl<<"Enter the interest rate as
percentage:";
cin>>interestRate;
//traverse through for loop from year 0 to numberOfYears
for( year = 0 ; year <= numberOfYears; year++)
{
if(year == 0) //if 0th year, set updatedAmount to principle
{
updatedAmount = principle;
}
else
{
//For the othr years calculate updatedAmount
//by adding annualAddition
//and then applying interest rate calculation on sum of above
two
updatedAmount = updatedAmount + annualAddition;
interestAdded = updatedAmount * interestRate/100;
updatedAmount = updatedAmount+ interestAdded;
}
//print year and the updatedAmount
cout<<endl<<"Year
"<<year<<":"<<"$"<<updatedAmount;
}
return 0;
}
==============================================
OUTPUT
==============================================
Run1
Enter the principle:2000
Enter the annual addition:300
Enter the number of years to grow:10
Enter the interest rate as percentage:10
Year 0:$2000
Year 1:$2530
Year 2:$3113
Year 3:$3754.3
Year 4:$4459.73
Year 5:$5235.7
Year 6:$6089.27
Year 7:$7028.2
Year 8:$8061.02
Year 9:$9197.12
Year 10:$10446.8
Run2:
Enter the principle:5000
Enter the annual addition:1000
Enter the number of years to grow:67
Enter the interest rate as percentage:10
Year 0:$5000
Year 1:$6600
Year 2:$8360
Year 3:$10296
Year 4:$12425.6
Year 5:$14768.2
Year 6:$17345
Year 7:$20179.5
Year 8:$23297.4
Year 9:$26727.2
Year 10:$30499.9
Year 11:$34649.9
Year 12:$39214.9
Year 13:$44236.3
Year 14:$49760
Year 15:$55836
Year 16:$62519.6
Year 17:$69871.5
Year 18:$77958.7
Year 19:$86854.5
Year 20:$96640
Year 21:$107404
Year 22:$119244
Year 23:$132269
Year 24:$146596
Year 25:$162355
Year 26:$179691
Year 27:$198760
Year 28:$219736
Year 29:$242809
Year 30:$268190
Year 31:$296109
Year 32:$326820
Year 33:$360602
Year 34:$397763
Year 35:$438639
Year 36:$483603
Year 37:$533063
Year 38:$587469
Year 39:$647316
Year 40:$713148
Year 41:$785563
Year 42:$865219
Year 43:$952841
Year 44:$1.04923e+06
Year 45:$1.15525e+06
Year 46:$1.27187e+06
Year 47:$1.40016e+06
Year 48:$1.54128e+06
Year 49:$1.6965e+06
Year 50:$1.86725e+06
Year 51:$2.05508e+06
Year 52:$2.26169e+06
Year 53:$2.48896e+06
Year 54:$2.73895e+06
Year 55:$3.01395e+06
Year 56:$3.31644e+06
Year 57:$3.64918e+06
Year 58:$4.0152e+06
Year 59:$4.41782e+06
Year 60:$4.86071e+06
Year 61:$5.34788e+06
Year 62:$5.88376e+06
Year 63:$6.47324e+06
Year 64:$7.12167e+06
Year 65:$7.83493e+06
Year 66:$8.61952e+06
Year 67:$9.48258e+06