Answer to Question #312954 in C++ for nickname

Question #312954

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:

  • implement robust "defensive programming" as discussed in class lecture.
  • document your source code properly

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


1
Expert's answer
2022-03-17T08:55:36-0400

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;
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment