Class Program: Help with Calculating Account Usage

I am hoping someone can help guide me in the right direction.
I have a project for class that I am working on and I could use some help. The project guidelines are below as well as my code thus far.
I have gotten this far with it but am having trouble specifically on accounting for the maximum hours in a month, and in Package B where it talks about charging $1 per 3-hour unit over 50 hours. Currently, my code is charging $1 per hour over 50 hours which is incorrect.
Thanks in advance for any assistance.

DROP LEAP YEAR REQUIREMENT
ASSUME FEB 672 hrs
An Internet service provider has three different subscription packages for its customers:

Package A: For $12 per month with 10 hours of access provided.
Additional hours are $2.00 per hour for the next
20 hours of usage. Then the charges are $1.00 for
each additional hour thereafter.
Assume usage is recorded in one-hour increments,
i.e., a 25-minute session is recorded as one hour.

Package B: For $18 per month with 20 hours of access provided.
Additional hours are $1.00 per hour for the next
30 hours of usage. Then the charges are $1.00 for
each additional 3-hour unit of usage thereafter,
i.e., 1 or 2 hour(s) of aggregated usage would be
charged $1.00.

Package C: For $25 per month with 200 hours access is provided.
Additonal $10 for the next 250 hours and an additional
$15 for usage over 450 hours.

Write a program that calculates a customerís monthly charges.
Must account for the maximum hours in a month.
Validate all input.

It just makes your code harder to read. You're testing an error condition here. If the test fails, i.e. you have a pkg number other than 1, 2 or 3, you want to exit or ask again. In your case, where you just exit, you want to do somthing like:

It just makes your code harder to read. You're testing an error condition here. If the test fails, i.e. you have a pkg number other than 1, 2 or 3, you want to exit or ask again. In your case, where you just exit, you want to do somthing like:

This also removes the extra level of indentation you have on your main program. Rule of thumb: The code path you are likely to take in most cases, should be at the lowest indentation level.

QuantumPete

I haven't gotten far enough in class yet to know, but why return 1? Basically it looks like you're just taking everything from the bottom of my code and moving it up to the top. Would this cause the code to run the same way?
Also, do you have any input about my questions in my initial post?

I haven't gotten far enough in class yet to know, but why return 1? Basically it looks like you're just taking everything from the bottom of my code and moving it up to the top. Would this cause the code to run the same way?
Also, do you have any input about my questions in my initial post?

It would run the same way. Consider this:

Code:

PSEUDOCODE:
if (some_condition_is_true) {
// Do all the things this prog is suppsed to do
} else {
// Print out an error message
// Exit
}

That's what you have. It's much clearer if you test that the condition is false, and then exit if it is.

Code:

if (some_condition_is_false) {
// Print out an error message
// Exit
}
// Do all the things this prog is supposed to do

As to the return 1. Have you come across the fact that in UNIX, every program will return a number to indicate whether it finished correctly or whether there was an error? 'return' will prematurely end your program and giving it a number can tell the user running your program that it finished incorrectly. By convention '0' means no errors, and all other numbers can be used to define exactly what went wrong.

QuantumPete

"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd

I am still trying to get some help with this. I am having trouble specifically on accounting for the maximum hours in a month, and in Package B where it talks about charging $1 per 3-hour unit over 50 hours. Currently, my code is charging $1 per hour over 50 hours which is incorrect.

At first glance it seems like you could use hrs/3 instead of hrs to charge $1/3 hours instead of $1/hour. But that's not quite right, because if 3, 4, or 5 hours were used, you'd get charged for only 3 hours. What you want is to overcharge them, right?

In that case you could use (hrs + 2) / 3. Think about it.

dwk

Seek and ye shall find. quaere et invenies.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

At first glance it seems like you could use hrs/3 instead of hrs to charge $1/3 hours instead of $1/hour. But that's not quite right, because if 3, 4, or 5 hours were used, you'd get charged for only 3 hours. What you want is to overcharge them, right?

In that case you could use (hrs + 2) / 3. Think about it.

I appreciate your input! Thank you!
What we're supposed to do is charge $1 for each 3-hour block of time over the set limit. So if you use 2 hrs, it'll round it up to 3 hours and charge you a dollar for it. Will you solution work in this case?

What we're supposed to do is charge $1 for each 3-hour block of time over the set limit. So if you use 2 hrs, it'll round it up to 3 hours and charge you a dollar for it. Will you solution work in this case?

Sure, just use the hours over the set limit instead of hrs. I guess you figured it out.

I'm not sure how to compensate for months with 28, 30 or 31 days, but I've got everything else working.

Something like this might help. I'm not sure if I have my leap-year algorithm right, you might want to check it.

If months are represented as numbers, you can simplify that further with month%2 -- but you have to be careful with July and August, which are both 31 days.

dwk

Seek and ye shall find. quaere et invenies.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

The leap year should also take into account that year % 100 is a NON-leap-year - besides, the code above is broken, because it will only be correct once we get to year 2400 - it requies that year is divisible by 4 AND by 400 at the same time, which in recent history is only year 2000.

So, if it's divisible by 4, and NOT even divisible by 100, or it is evenly divisible by 400, it is a leap-year.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell