The program question An investor has the opportunity to inve
The program question: An investor has the opportunity to invest a minimum of $10,000 in an investment. We want to write a program to help him/her determine the future value of the investment.
This is the sample run of what the program is supposed to accomplish:
Enter the amount of the investment.
The minimum investment is $10,000.00.
5000 [Enter] Error, the minimum investment is $10,000.00.
Enter the amount of the investment: 10000 [Enter]
Enter the annual interest rate: -3 [Enter] Error, the interest rate should be positive.
Enter the annual interest rate: 3 [Enter]
Enter the number of months of the investment: -12 [Enter] Error, the number of months should be positive.
Enter the number of months of the investment: 12 [Enter]
After 12 months your investment of $10000.00 will be worth $10304.16.
Below is the working program that I have managed to write!
#include
#include
using namespace std;
int main()
{
int numberofMonths;
double investmentAmount, interestRate;
cout << fixed << setprecision(2);
cout << \"Enter your initial investment of atleast $10,000. \" << endl;
cin >> investmentAmount;
while (investmentAmount < 10000)
{
cout << \"Error, the minimum investment $10,000.\" << endl;
cout << \"Enter the amount of investment: \";
cin >> investmentAmount;
}
cout << \"Enter your annual interest rate. \" << endl;
cin >> interestRate;
while (interestRate < 0)
{
cout << \"Error, the interest rate should be positive.\" << endl << \" Enter the annual interest rate: \";
cin >> interestRate;
}
cout << \"Ener the number of months of the investment: \";
cin >> numberofMonths;
while (numberofMonths < 0)
{
cout << \"Error, the number of months should be positive.\" << endl << \"Enter the number of months of investment: \";
cin >> numberofMonths;
}
double investmentBalance = investmentAmount + ((investmentAmount * numberofMonths * interestRate)/1200);
cout << \"After \" << numberofMonths << \"Months your investment of $\" << investmentAmount << \" Will be worth $\" << investmentBalance << endl;
system(\"pause\");
return 0;
}
My problem is that after I debugg the program and input all the given sample.. The balance becomes 10300, instead of 10304.16
Could you tell me what I have to correct in my code?
I do Believe it is a problem with my investment balance equation.
All they told me was that monthly interest rate = ((annual/12)/100)
Solution
solution
#include<stdio.h>
#include<iomanip>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
int numberofMonths;
double investmentAmount, interestRate;
cout << fixed<<setprecision(2);
cout << \"Enter your initial investment of atleast $10,000. \" << endl;
cin >> investmentAmount;
while (investmentAmount < 10000)
{
cout << \"Error, the minimum investment $10,000.\" << endl;
cout << \"Enter the amount of investment: \";
cin >> investmentAmount;
}
cout << \"Enter your annual interest rate. \" << endl;
cin >> interestRate;
while (interestRate < 0)
{
cout << \"Error, the interest rate should be positive.\" << endl << \" Enter the annual interest rate: \";
cin >> interestRate;
}
cout << \"Ener the number of months of the investment: \";
cin >> numberofMonths;
while (numberofMonths < 0)
{
cout << \"Error, the number of months should be positive.\" << endl << \"Enter the number of months of investment: \";
cin >> numberofMonths;
}
//you need to find based on this formula
//investmentbalance=(investmentamount*(1+annual interest Rate/no of times compounded per year)^ (no of times compounded * times in years))
double timeinyears=numberofMonths/12;
double annualinterestRate=interestRate/100;
double monthlyinterestRate=(interestRate/12)/100;
double nooftimescompoundedperyear=12;
double investmentBalance=(double)investmentAmount*pow((1+annualinterestRate/12),(12*timeinyears));
//double investmentBalance =investmentAmount + ((investmentAmount * numberofMonths * interestRate)/1200);
cout << \"After \" << numberofMonths << \"Months your investment of $\" << investmentAmount << \" Will be worth $\" << investmentBalance << endl;
system(\"pause\");
return 0;
}
output
Enter your initial investment of atleast $10,000.
5000
Error, the minimum investment $10,000.
Enter the amount of investment: 15000
Enter your annual interest rate.
3
Ener the number of months of the investment: 24
After 24Months your investment of $15000.00 Will be worth $15926.36
Enter your initial investment of atleast $10,000.
10000
Enter your annual interest rate.
3
Ener the number of months of the investment: 12
After 12Months your investment of $10000.00 Will be worth $10304.16


