Write a program that inputs a dollar amount to be printed on a check then prints the amount in check-protected format with leading asterisks if necessary. Assume that nine spaces are available for printing an amount.
Computers are frequently employed in check-writing systems such as payroll and accounts-payable applications. Many strange stories circulate regarding weekly paychecks being printed (by mistake) for amounts in excess of $1 million. Weird amounts are printed by computerized check-writing systems, because of human error or machine failure. Systems designers build controls into their systems to prevent such erroneous checks from being issued. Another serious problem is the intentional alteration of a check amount by someone who intends to cash a check fraudulently. To prevent a dollar amount from being altered, most
computerized check-writing systems employ a technique called check protection.
Checks designed for imprinting by computer contain a fixed number of spaces in which the computer may print an amount. Suppose that a paycheck contains eight blank spaces in which the computer is supposed to print the amount of a weekly paycheck. If the amount is large, then all eight of those spaces will be filled, for example,
1,230.60 (check amount)
--------
12345678 (position numbers)
On the other hand, if the amount is less than $1000, then several of the spaces would ordinarily be left blank. For example,
99.87
--------
12345678
contains three blank spaces. If a check is printed with blank spaces, it’s easier for someone to alter the amount of the check. To prevent a check from being altered, many check-writing systems insert leading asterisks to protect the amount as follows:
***99.87
--------
12345678
```
#include
#include
using namespace std;
int main()
{
double amount;
double base = 100000.0;
int i;
cout << "Enter check amount: ";
cin >> amount;
cout << "The protected amount is $";
// calculate how many leading asterisks to insert
for ( i = 0; amount < base; i++ )
base /= 10;
// insert the asterisk(s)
for ( int j = 1; j <= i; j++ )
cout << '*';
cout << fixed << setw( 9 - i ) << setfill( '*' )
<< setprecision( 2 ) << amount << endl;
return 0; // indicates successful termination
} // end main
```
Enter check amount: 22.88
The protected amount is $****22.88
You might also like to view...
To display the horizontal and vertical rulers, select the Ruler check box on the:
A) Presentation Views options group. B) DISPLAY tab. C) status bar. D) VIEW tab.
The ________ property is used to create an informative label that appears at the top of a table column in Datasheet view
A) caption B) text C) required D) description