I need my output to print next 10 years Got alot of Code fig
I need my output to print next 10 years Got alot of Code figured out Code at bottom
Rachael and Cody recently graduated from college and are looking to wisely invest part of their graduation gift money in Roth 401Ks. Rachael has $2000 to invest and Cody has $5000. When it comes to investing, Rachael is more of a risk taker and wants to invest in a mutual fund which historically has a growth rate of 8% while Cody is more conservative and wants to invest in a fund which typically grows at 2%. Rachael feels that if she stays invested long-term in risker diversified mutual funds with the $2000, her Roth account will have more value than Cody\'s. Furthermore, by the time she retires, she thinks her account will be worth significantly more and she would like to prove this to Cody.
Write and test a program which allows a user to put in 2 mutual fund names and for each one, an initial amount of money and a growth rate. For each fund, the user is supposed to input the fund name, initial deposit and growth rate. (NOTE : the initial deposit of the first fund is always less than second fund\'s initial deposit and growth rate of first fund is always greater than second fund\'s growth rate).
Possible pseudocode :
Declare variables
prompt user and read fund 1 name, amount of initial deposit and growth rate
prompt user and read fund 2 name, amount of initial deposit and growth rate
while (fund1 amount < fund 2 amount)
calculate balance for fund 1 after a year
calculate balance for fund 2 after a year
Add +1 to YEAR
Output results for when fund 1 overtakes fund 2
Output heading line for future year\'s information
Calculate Y10 : Y10 = YEAR + 10
Use for statement to calculate and output fund amounts for next 10 years
CODE:
#include<iostream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
cout<<fixed<<showpoint<<setprecision(2);
double inv1,inv2,in1,in2;
double growth1,growth2;
cout<<\"\ Enter Investment Number 1 :\";
cin>>inv1;
cout<<\"\ Enter Investment 2: \";
cin>>inv2;
cout<<\"\ Enter growth rate for Investment 1 : \";
cin>>growth1;
cout<<\"\ Enter growth rate 2: \";
cin>>growth2;
in1=inv1;
in2=inv2;
int year=1;
while(inv1<inv2)
{
inv1=inv1+(inv1*(growth1/100));
inv2=inv2+(inv2*(growth2/100));
year++;
}
cout<<\"At that point:\"<<endl;
cout<<\"The value of Fund A is $\" <<inv1<<endl;
cout<<\"The value of Fund B is $\" <<inv2<<endl;
cout <<\"Longer term results :\"<<endl;
for(int i=1;i<=10;i++)
{
in1=in1+(in1*(growth1/100));
in2=inv2+(in2*(growth2/100));
}
cout<<setw(4)<<\" Year\"<<setw(13)<<\"Fund A\"<<setw(17)<<\" Fund B\"<<endl;
cout<<setw(4)<<year<<setw(15)<<in1<<setw(17)<<in2<<endl;
return 0;
}
Solution
#include<iostream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
cout<<fixed<<showpoint<<setprecision(2);
double inv1,inv2;
double growth1,growth2;
cout<<\"\ Enter Investment Number 1 :\";
cin>>inv1;
cout<<\"\ Enter Investment 2: \";
cin>>inv2;
cout<<\"\ Enter growth rate for Investment 1 : \";
cin>>growth1;
cout<<\"\ Enter growth rate 2: \";
cin>>growth2;
int year=1;
while(inv1<inv2)
{
inv1=inv1+(inv1*(growth1/100));
inv2=inv2+(inv2*(growth2/100));
year++;
}
cout<<\"\ after \"<<year<<\"years the value of fund A is greater than fund B\";
cout<<\"At that point:\"<<endl;
cout<<\"The value of Fund A is $\" <<inv1<<endl;
cout<<\"The value of Fund B is $\" <<inv2<<endl;
cout <<\"Longer term results :\"<<endl;
cout<<setw(4)<<\" Year\"<<setw(13)<<\"Fund A\"<<setw(17)<<\" Fund B\"<<endl;
int y10=year+10;
for(int i=year+1;i<=y10;i++)
{
inv1=inv1+(inv1*(growth1/100));
inv2=inv2+(inv2*(growth2/100));
cout<<setw(4)<<i<<setw(15)<<inv1<<setw(17)<<inv2<<endl;
}
return 0;
}


