Calculating fee charges

Can't put into the right words for what I need to ask, so I'll explain what's going on.

Say an internet charge costs $9.95 a month for up to 10 hours of use. There's an additional $2.00 per hour after that.

I can't get my program to calculate that correctly. The whole program executes perfectly, except for that bit. For 11 hours, the amount should be $11.95, for 12 hours, it's $13.95, etc.

All of my switch statements are set up like this. This is just the first one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
switch (choice)
         {
              case PACKAGE_A_CHOICE:
                    
                  if (hours < PACKAGE_A_HOURS || hours == PACKAGE_A_HOURS)

                      charges = PACKAGE_A_BASE;

                  else if (hours > PACKAGE_A_HOURS)
                  {
                      extraHours++;

                      charges = PACKAGE_A_BASE + (extraHours * 2.00);
                  }

              break;


I've initialized int extraHours = 0. I thought that by multiplying the counter by 2.00 would add that amount to the charge, but for each extra hour over 10, the amount is still only an extra $2.

Is my full code really needed? I only need a push in the right direction for how to do this calculation.
Last edited on
I don't know why the code came out like that. It looks fine in my IDE.
Using extraHours this way doesn't make sense [wihout a loop]. So what you want is the difference between the base hours and the acutal hours:

1
2
3
                      extraHours = hours - PACKAGE_A_HOURS;

                      charges = PACKAGE_A_BASE + (extraHours * 2.00);
Last edited on
Because I was trying to use a counter, yeah? I thought so, I just couldn't think of how to get the amount of extra hours. Can't believe it was that simple. Thank you. I tried everything except subtracting. Right in my face.
Last edited on
Topic archived. No new replies allowed.