views:

68

answers:

4

I have the following question, and what I'm most confused on, is how to do the logic for determining if a check is one month late or not.

Question is:

"Write pseudocode for a program that calculates the service charge of a customer owes for writing a bad check. The program accepts a customer's name, the date the check was written (year, month and day), the current date (year, month and day), 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 percent 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 1."

So far what I have write now is:

Start
  string Name
  num AmountOwed
  num DateCheckWritten
  num CurrentDate
  num CheckAmount
  get Name, DateCheckWritten, CurrentDate, CheckAmount
  while eof
A: 

I'm not sure where your problem lies, but I think you have two issues to deal with:

  1. What is the definition of late?
  2. How many months late is this check?

So in my pseudocode, I would have a step that determines how late a check is, and then another step to calculate the fee. Inside the first step, you could just subtract the days and divide. But the directions say as soon as a new month comes along, it is one month late. So all you really have to do is subtract months.

Not sure what else you are asking, but it appears you are asking for guidance, not code. Hope this helps.

MJB
A: 

I'm going to assume this is homework, and as such I'll try to just point you in the right direction.

If you assign numbers to each month (Jan = 1, Feb = 2, etc) then the number of months between two dates is easy to determine - how many months are there between September (= 9) and May (= 5)?

The other thing to take into account is the year - for each year the check is late, you'll also have to add another twelve months. This works the same as for months.

Need any extra detail, feel free to let me know.

Mac
Mac - We are on the same page on how to determine it logically in that sense, but i'm confused moreless how to say that in pseudocode.I know the date output is 8 numeric digits long following (year, month, day)XXXXXXXX 'Example being Setp 30 2010 would be: 20100930Would the correct thing to do in psedocode would be to seperate into their own seperate values? so use the following:num CurrentDateMonthnum CurrentDateDaynum CurrentDateYearnum CheckDateMonthnum CheckDateDaynum CheckDateYearthen do psedocode to subtract off the months and find out how many etc?
eqiz
A: 

Simplify, hit the main points and then break it down more and more, write it how you would tell your grandma it worked.

you might start out with something like

Start
While there are more bad checks
  get the service charge 
  add the service charge to the account
record the updates

get the service charge
  charge starts at $20
  add to the charge $5 multiplied by number of months
Greg Domjan
+1  A: 

Since you don't have to deal with days, the algorithm is very straightforward:

MonthsLate = (CurrentDate.Year - DateCheckWritten.Year) * 12 
                  + (CurrentDate.Month - DateCheckWritten.Month)

Good luck with the rest of the problem!

John Rasch
I'm just going to use this in the appropriate place. Thanks to everyone for helping me solve this I'll know what to do from here on out. I know VB.NET/C etc but I still get lost sometimes on how they expect me to explain pseudocode when they haven't used examples of .Events or references.
eqiz