Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Requirement (What you need to do) You are asked to write a program that takes as input a dollar amount, and then displays the

The Requirement (What you need to do)

You are asked to write a program that takes as input a dollar amount, and then displays the dollar amount in English (similar to how you would write the amount in a check).

Use case (Scenario)

$PrintDollar Enter the dollar amount:$23.45 It's twenty three and 45/100 Try again(y/n):n Bye! 

Error handling: You are required to handle the following error inputs. If the input is any of the following case, your program should display appropriate error message, and ask the user to try again.

  1. The dollar amount cannot be greater than 9999.99
  2. The dollar amount cannot be negative
  3. There are at most two decimal digitals in the input
  4. Handle non-digit input, such as ten

Note on handling error in input operation

bool wrongInput; do { //attempt to read an int, a char, and another int cin >>dollar >>ch >> cents; if (cin.fail()) //in case the abvoe fails, e.g., ten dollor five cents... { cout <<"Wrong input types. Try again: "; cin.clear(); //clear the error flags in cin cin.ignore (2048,' '); //ignore everthing in the input buffer, up to 2048 char, //up to the newline char =< ignore the rest of the line wrongInput = true; } else wrongInput = false; } while (wrongInput); 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Refer to Problem 10-1. What is the projects PI?

Answered: 1 week ago

Question

Understand why empowerment is so important in many frontline jobs.

Answered: 1 week ago