# solve it plz

Discussion in 'C' started by cooop, Jul 14, 2009.

1. ### cooopNew Member

Joined:
Jul 8, 2009
Messages:
19
0
Trophy Points:
0
A baby sitter charges \$1.50 per hour until 9:00 pm (while the kids are still up), \$1.00 per hour between 9:00 pm and midnight, and \$1.25 per hour after midnight (since late night baby sitting interferes with morning classes).
Write a program that reads the sitter's starting time in hours and minutes and the ending time in hours and minutes and then computes the sitter's fee. Assume all times are between 6:00 pm and 6:00 am; hours should be entered as numbers on a 12-hour clock, so that hour 3 should be considered as 3:00 am and hour 8 should be considered as 8:00 pm. Hours outside the range 1 to 12 should be considered invalid.
[Note: You may not use a 24 hour clock for this problem. Also, times must be given in hours and minutes (as two nonnegative integer values).]

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
How far have you got and where are you stuck? We won't write the code for you, but we will help.

3. ### fob500New Member

Joined:
Jul 12, 2009
Messages:
24
0
Trophy Points:
0
Hey coop.Are You posting your school homework ??:nonod:
I suggest you try out these programs yourself and then ask for help.Trust me it would help you to learn.Still I think a lot of members would be willing to help if you try atleast and paste some code.No one will do it for you.Also I guess you are starting with c/c++
I suggest you see this http://www.codersource.net/codersource_cppprogramming.html
.It would help you with the basics.
Otherwise if you don't really want to do that I suggest you search google there are thousands of programs(maybe if you are lucky you might find a program which does similar to what you want to do) this way you'll have a better chance completing your program(if you really dont want to do it yourself).Hope that helped

4. ### cooopNew Member

Joined:
Jul 8, 2009
Messages:
19
0
Trophy Points:
0
No I just want the idea how to solve it

5. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
Try working it out yourself on paper first. Decide on a few start and stop times and work out the fees for each block. After you've done a few you'll get the hang of how to do it and at that point you'll be able to start coding it up.

So for example let's say she works 1830-0100. That'll be 1.50 per hour from 1830-2100 (how many hours is that, then multiply the number of hours by the rate), 1.00 per hour from 2100-0000 (same: hours * rate) and 1.25/h from 0000-0100. Then work out the total price.

You'll need to get some input from the user - just four numbers, which for the above example would be 6 30 1 0. Check the numbers are in range and display an error if they're not. Then if the numbers are correct, proceed with the above calculation. The assignment doesn't say anything about checking validity of the minutes but you should add that anyway.

Also work it out step by step. Start with the input and the validation. Make sure that works before moving on to the next step. Then write the code for the first time zone (before 9pm) and display the time, rate and fee just for that block, and make sure this matches your calculations for that zone. Then add the second zone and test, and finally the 3rd zone (after midnight). While you're writing the code you can display a lot more than the final program will, just so you can be sure you're on track. Once the program is complete you can remove the extra output so that the program just outputs a single number - the fee for the overall event.

Take it step by step and it becomes really easy. Trying to write the whole lot in one go is probably where you're getting lost.

6. ### cooopNew Member

Joined:
Jul 8, 2009
Messages:
19
0
Trophy Points:
0
how can i write the hours and minutes also am,pm in if statment ??
You may not use a 24 hour clock for this problem << then how i can write it ?

7. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
It's down to how you interpret the numbers entered. Half past six would be entered as two numbers: 6 and 30. You don't have to use 24 hour clock to make sense of 6 30 as 6:30.

I don't understand the question "how can i write the hours and minutes also am,pm in if statment ??" What if statement are you trying to write?

8. ### cooopNew Member

Joined:
Jul 8, 2009
Messages:
19
0
Trophy Points:
0
nested if ?

9. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
Yeah but what is going into the if. If (what) - so what's "what" is what I mean, what?

10. ### cooopNew Member

Joined:
Jul 8, 2009
Messages:
19
0
Trophy Points:
0
why u don`t solve it
really i don`t know how 2 solve it ((((

11. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
0
Occupation:
Senior Support Engineer
Location:
England
Cos it's not my homework. You solve it because you want the credit, or you don't bother if you want to fail. There's no point you passing off our work as your own - it teaches you absolutely nothing.

So either roll your sleeves up and get working, or quit the course if you're a quitter. We will HELP you, but if you're not interested, which seems to be the case, then there's not a lot we can do for you.

Joined:
Jul 12, 2004
Messages:
15,292