Improve the source code from class lecture (see the starter code) to display error messages if the user enters non numeric values. Also, the program needs to present the user with an error message if the initial deposit is more than their financial goal ($10,000).
Note: In order to get full credit for this exercise, you need to:
Sample Program Run:
Enter your initial deposit $:
Your initial $1800 needs 287 years to mature to $10020.6
Another Sample Program Run:
Enter your initial deposit $:
Invalid input!
Please enter your initial deposit (less than $10K):
Invalid input!
Please enter your initial deposit (less than $10K):
Invalid input!
Please enter your initial deposit (less than $10K):
Your initial $6123.88 needs 82 years to mature to $10001.4
Here is program:
int main()
{
int deposit;
int year;
double totaldeposit;
cout << "Please enter your initial deposit (less than $10K): " << endl;
cin >> deposit;
if (deposit >= 10000)
{
cout << "Invalid input!" << endl;
}
else
{
for (year < 10000; year++;)
{
totaldeposit = deposit * year;
}
cout << "Your initial " << deposit << " needs " << year << " years to mature to " << "$" << totaldeposit << endl;
}
}
Comments
Leave a comment