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 $: [ user enters 1800]
Your initial $1800 needs 287 years to mature to $10020.6
Another Sample Program Run:
Enter your initial deposit $: [user enters -1]
Invalid input!
Please enter your initial deposit (less than $10K): [user enters 0]
Invalid input!
Please enter your initial deposit (less than $10K): [user enters 8000]
Your initial $8000 needs 38 years to mature to $10041.8
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