Okay, so like many others i have an issue. I have written a pseudocode that is supposed to represent the issue below.

#1 Write pseudocode for a program that calculates the service charge a customer owees for writing a bad check. Okay, i got everything right except my teacher turned back to me saying that she wants to give me credit, but I am missing another "get" or this will end up in infinite loop. I am confused, I printed out output and put a stop. I am definitely missing something and have gotten 100% in class so far.

I will never post anything I haven't worked on, and just hope for a little extra push in the right direction from some individuals who know the answer. TIA

Here is my code

Start
Get input 
      currYY
      curmm
      curdd
      chkYY
      chkmm
      chkdd
      chkAmount
             While not eof
                       chkAmount1 = 20 + chckAmount * .02
                       chkAmount2 = 12*(currYY – chkYY) + (curmm – chkmm) *5  
                       chkAmount1 + chckAmount2 = chkFee
              print calculatedAnswer chkFee      
              End While
Stop

Dani AI

Generated

A short explanation and a concrete, safe pattern for the missing GET. In this context a GET is simply "read the next input record" (from a file or stream). Two common, correct patterns avoid an indefinite loop: (1) do a priming read before entering a loop and then read the next record at the end of each loop iteration, or (2) perform the read as part of the loop condition so the loop only runs when a new record is obtained. Echoing and , the teacher was pointing out the priming-read pattern: the program must advance the input inside the loop so the same record is not processed repeatedly.

# priming read
ReadRecord(custName, chkY, chkM, chkD, curY, curM, curD, amount)

WHILE not EOF
    monthsLate = (curY - chkY) * 12 + (curM - chkM)
    if monthsLate < 0 then monthsLate = 0

    fee = 20.00 + 0.02 * amount + 5.00 * monthsLate
    fee = RoundToCents(fee)

    Print(custName, fee)

    # advance input - this is the GET the teacher referenced
    ReadRecord(custName, chkY, chkM, chkD, curY, curM, curD, amount)
END WHILE

Notes and pitfalls: clamp negative month values to zero (future-dated checks should not produce negative late months). The problem states a new calendar month counts as a month late, so days do not change the month count calculation above. Use integer cents or a decimal/currency type when available to avoid floating-point rounding errors and call a rounding function before printing. When reading interactively versus reading from a file, EOF behavior differs; the same priming/read-at-end pattern still applies. This explanation implements the extra GET the teacher requested and aligns with the hints from and while fixing the indefinite-loop issue noted by .

Recommended Answers

All 6 Replies

Well your while not eof implies that you need to read input inside the loop.
Did you even want a loop here?

I suppose I should post the assignment so I can clear that up. Basically the check should keep incurring charges monthly on the 1st until check is paid. Hence the reason for my get while. I believe this seems strange that both gets are during the while, but for some reason my teacher said this was fine, I am just missing a get. I know I'm missing something here.

Here is the actual question

Design a pseudocode for a program that calculates the service charge a customer owes for writing a bad check. Program accepts customers name, the date the check was written, the current date, and the amount of the check in dollars and cents. The program continues until an eof value is encountered. The service charge is $20 plus 2% of the amount of the check, plus $5 for every month that has passed since the check was written. A check is one month late as soon as a new month starts - so a bad check written on September 30 is one month overdue on October 1st.

Well, here is what my teacher wrote.

There should be another GET following the print. If it is not there, you will be in an indefinite loop. You read the first record prior to the WHILE. The first statements process the record you read first. After that happens, which is after the print, you need to get the next record to process. Otherwise, you will just process the first record again.

If that does not make sense, let me know. I am sending this back so that you can get the second Get in.

I guess my issue is...What are you "getting"?


I guess my issue is...What are you "getting"?

Something from the file :)

The teacher means that you'll have to read something from the file in the while !eof loop.

So something like :

While not eof
    read stuff from file
    do stuff

Thank you very much, I think i am getting it. I'll post the response. Thanks to all of you for making me figure this out. That's what I needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.