1

i have the following question:

Computers are frequently used in check-writing systems, such as payroll and accounts payable applications. Many stories circulate regarding weekly pay- checks being printed (by mistake) for amounts in excess of $1 million. Weird amounts are printed by computerized check-writing systems because of human error and/or machine failure. Systems designers, of course, make every effort to build controls into their systems to prevent erroneous checks from being issued. Another serious problem is the intentional alteration of a check amount by some- one who intends to cash it 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 a paycheck contains nine blank spaces in which the com- puter is supposed to print the amount of a weekly paycheck. If the amount is large, then all nine of those spaces will be filled

for example:

11,230.60 (check amount)
---------
123456789 (position numbers)

On the other hand, if the amount is less than $1000, then several of the spaces will ordinarily be left blank—for example,

99.87
---------
123456789

contains four blank spaces. If a check is printed with blank spaces, it is 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
---------
123456789

Write a program that inputs a dollar amount to be printed on a check and then prints the amount in check-protected format with leading asterisks if necessary. Assume that nine spaces are available for printing an amount.

im not asking anyone to write the code for me or anything, i just need a starting point, we have this huge list of all these different functions, can anyone recommend what function i could use from the string-handling library?

0

3 Answers 3

2

Think about the relationship between the number of digits to be printed and the number of asterisks that should precede the digits. They should add up to a constant, in this case 9. So if you get the length of the digit string you're going to print, you can determine how many asterisks to print first.

Sign up to request clarification or add additional context in comments.

1 Comment

I don't know why I first thought of this in terms of mashing stuff into an array. TMTOWTDI.
2

I won't do your homework for you, but I will encourage you to look at the following functions:

sprintf - formatted output.

Hint: 0 pad the output on the left

strspn / strcspn - count spans of characters in / not in a set of characters

Hint: replace the extra zeroes.

memset - fill memory region with a byte value

I'm assuming you know how to do pointer arithmetic with characters and "strings" in C. If not, study up. I'm also assuming ASCII, rather than unicode. If it's unicode, you can teach me how to do it in C :-)

1 Comment

haha nah it's in ascii :), the topic is strings and characters now, so i'm just attempting the questions, doing pretty good just finishing up this one now :) thanks for the help!
0
  1. Convert amt by using itoa and find length

  2. Now substract length from 9(Max no.of digits) you get the no of asterisks to be printed

  3. Print that no.of asterisks and then your Amt.


int amt,count;
char s[10];
printf("Enter Amt");
scanf("%d",&amt);

/* Store Amount as String */
itoa(amt,s,10);

/* Calculate Count  */
count=9-strlen(s);

/* Print asterisks */
for(int i=0;i<count;i++)
printf("*");

/* Print Amount */
printf("%d",amt);

5 Comments

thanks! ill give it a shot now :) how would i perform the subtraction?
9-strlen(s) where s is string that stores converted amt
i have define itoa as apart of <string.h> but it sais it is undeclared? any reasons why?
edit: itoa apparently isn't in any of the standards, i used snprintf and it works fine :)
Use Header file include<stdlib.h>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.