Continuing the discussion of the previ- ous example, we reiterate the importance of designing check-writing systems to prevent alteration of check amounts. One common security method requires that the check amount be both written in numbers and “spelled out” in words. Even if someone is able to alter the numerical amount of the check, it’s extremely difficult to change the amount in words.
Write a program that inputs a numeric check amount and writes the word equivalent of the amount. Your program should be able to handle check amounts as large as $99.99. For example, the amount 112.43 should be written as ONE HUNDRED TWELVE and 43/100
What will be an ideal response?
```
// NOTE: THIS PROGRAM ONLY HANDLES VALUES UP TO $99.99
// The program is easily modified to process larger values
#include
using namespace std;
int main()
{
// array representing string of values from 1-9
const char *digits[ 10 ] = { "", "ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT", "NINE" };
// array representing string of values from 10-19
const char *teens[ 10 ] = { "TEN", "ELEVEN", "TWELVE", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN",
"SEVENTEEN", "EIGHTEEN", "NINETEEN"};
// array representing string of values from 10-90
const char *tens[ 10 ] = { "", "TEN", "TWENTY", "THIRTY", "FORTY",
"FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY" };
int dollars;
int cents;
int digit1;
int digit2;
cout << "Enter the check amount (0.00 to 99.99): ";
cin >> dollars;
cin.ignore();
cin >> cents;
cout << "The check amount in words is:\n";
// test if the integer amount correspond to a certain array
if ( dollars < 10 )
cout << digits[ dollars ] << ' ';
else if ( dollars < 20 )
cout << teens[ dollars - 10 ] << ' ';
else
{
digit1 = dollars / 10;
digit2 = dollars % 10;
if ( !digit2 )
cout << tens[ digit1 ] << ' ';
else
cout << tens[ digit1 ] << "-" << digits[ digit2 ] << ' ';
} // end else
cout << "and " << cents << "/100" << endl;
return 0; // indicates successful termination
} // end main
```
Enter the check amount (0.00 to 99.99): 72.68
The check amount in words is:
SEVENTY-TWO and 68/100
You might also like to view...
In Excel, the ampersand allows the data in two or more fields to be combined
Indicate whether the statement is true or false
The VLOOKUP function finds values by searching across the first row of the lookup table
Indicate whether the statement is true or false.