hey guys,
let me first post the code, so you know what I am talking about...
It is a bit long.
| Code: |
/*
Write an interactive C++ program to prompt the user for an amount of money to be invested and an interest rate.
The given amount of money is to be invested at the interest rate indicated (with annual compouding), and the
number of years until the amount of money is doubled is to be determined. Display on the screen a list of values
of this investment at the beginning of each year, interest earned during the year and the value of the investment
at the end of the year until the investment (at least) doubles.
Sample input might be $1000 invested at a rate of 5%. You will input the interest rate as a percentage.
A partial chart follows:
Year Year Begin $ Interest Year End $
1 1000.00 50.00 1050.00
2 1050.00 52.50 1102.50
This chart would continue until the amount of the money at the end of a year is double the original amount.
Use a while statement to implement the loop
*/
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
int year;
float interest, balance, investedamount;
cout << setiosflags (ios :: fixed | ios :: showpoint);
cout << setprecision (2);
cout << "Please enter the amount of money to be invested: $";
cin >> investedamount;
cout << "Please enter the percentage of interest rate: ";
cin >> interest;
cout << endl;
cout <<"The Amount you have invested is $"<<investedamount<<endl;
cout <<"The Interest Rate on investment is "<<interest<<"%"<<endl;
cout <<endl;
interest = interest/100;
balance = investedamount;
year = 0;
cout << "Year/s" <<" Year Begin $"<< " Interest"<<" Year End $"<<endl;
cout << endl;
while (balance <= investedamount*2)
{
balance = interest * balance + balance;
year=year+1;
cout <<setw(3)<< year; // Year/s
cout <<setw(22)<< balance; // Year Begin $
cout <<setw(19)<< interest*balance; // Interest
cout <<setw(23)<< balance+interest*balance<<endl; // End Year $
}
cout <<endl;
} |
ok, so according to the sample that my professor gave, Year 1 should have a Begin amount of $1000.00
I am not getting 1000.00 Year Begin $ for Year1
This is what I am getting..
| Code: |
Year Year Begin $ Interest Year End $
1 1050.00 52.50 1102.50
2 1102.50 55.13 1157.63
|
it is suppose to look like this..
| Code: |
Year Year Begin $ Interest Year End $
1 1000.00 50.00 1050.00
2 1050.00 52.50 1102.50
3 1102.50 55.13 1157.63
|
can anyone help! i'd really appreciate it...
thank you soo much! 