need in C++ and not using DO loop. Needs to be exactly like the examples and all
ID: 3863504 • Letter: N
Question
need in C++ and not using DO loop. Needs to be exactly like the examples and all in one program! Please in C++ ONLY! No void docalc etc.
Ask the user for an amount to save each month. Assuming a 1% per month interest rate, how many MONTHS will it take the user to save $1000. Add the savings at the END of each month. For example:
How much do you want to save each month? 90 Month 1: $0 deposited 90 interest earned is 0.9 Month 2: $90.9 deposited 90 interest earned is 1.809 Month 3: $182.709 deposited 90 interest earned is 2.72709 Month 4: $275.436 deposited 90 interest earned is 3.65436 Month 5: $369.09 deposited 90 interest earned is 4.5909 Month 6: $463.681 deposited 90 interest earned is 5.53681 Month 7: $559.218 deposited 90 interest earned is 6.49218 Month 8: $655.71 deposited 90 interest earned is 7.4571 Month 9: $753.167 deposited 90 interest earned is 8.43167 Month 10: $851.599 deposited 90 interest earned is 9.41599 Month 11: $951.015 deposited 90 interest earned is 10.4102 It took 11 months, and you now have $1051.43
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
float monthlysaving;
float interest=0;
float totalsave=0;
int monthcount=0;
float p=0;
cout <<"How much do you want to save each month? " ;
cin>>monthlysaving;
//totalsave <1000
while( totalsave<1000)
{
monthcount=monthcount+1;
p=totalsave + monthlysaving;
interest=p/100;
cout<<"Month "<<monthcount<<": $"<<totalsave<<" deposited "<<monthlysaving<<" interest earned is "<<interest<<endl;
totalsave=p+interest;
}
cout<<"It took "<<monthcount<<" months, and you now have $ "<<totalsave;
return 0;
}
--------------------------------------------------------
output sample 1:-
How much do you want to save each month? 100
Month 1: $0 deposited 100 interest earned is 1
Month 2: $101 deposited 100 interest earned is 2.01
Month 3: $203.01 deposited 100 interest earned is 3.0301
Month 4: $306.04 deposited 100 interest earned is 4.0604
Month 5: $410.1 deposited 100 interest earned is 5.10101
Month 6: $515.201 deposited 100 interest earned is 6.15201
Month 7: $621.354 deposited 100 interest earned is 7.21354
Month 8: $728.567 deposited 100 interest earned is 8.28567
Month 9: $836.853 deposited 100 interest earned is 9.36853
Month 10: $946.221 deposited 100 interest earned is 10.4622
It took 10 months, and you now have $ 1056.68
------------------------------------------------------------------------
output sample 2:-
How much do you want to save each month? 90
Month 1: $0 deposited 90 interest earned is 0.9
Month 2: $90.9 deposited 90 interest earned is 1.809
Month 3: $182.709 deposited 90 interest earned is 2.72709
Month 4: $275.436 deposited 90 interest earned is 3.65436
Month 5: $369.09 deposited 90 interest earned is 4.5909
Month 6: $463.681 deposited 90 interest earned is 5.53681
Month 7: $559.218 deposited 90 interest earned is 6.49218
Month 8: $655.71 deposited 90 interest earned is 7.4571
Month 9: $753.167 deposited 90 interest earned is 8.43167
Month 10: $851.599 deposited 90 interest earned is 9.41599
Month 11: $951.015 deposited 90 interest earned is 10.4102
It took 11 months, and you now have $ 1051.43
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.