Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   solve it plz (http://www.go4expert.com/forums/solve-it-plz-t18540/)

cooop 15Jul2009 00:03

solve it plz
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).]

xpi0t0s 15Jul2009 05:12

Re: solve it plz
How far have you got and where are you stuck? We won't write the code for you, but we will help.

fob500 15Jul2009 10:06

Re: solve it plz
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/codersour...ogramming.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

cooop 15Jul2009 12:26

Re: solve it plz
No I just want the idea how to solve it

xpi0t0s 15Jul2009 13:20

Re: solve it plz
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.

cooop 16Jul2009 01:07

Re: solve it plz
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 ?

xpi0t0s 16Jul2009 02:48

Re: solve it plz
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?

cooop 16Jul2009 02:51

Re: solve it plz
nested if ?

xpi0t0s 16Jul2009 03:00

Re: solve it plz
Yeah but what is going into the if. If (what) - so what's "what" is what I mean, what?

cooop 16Jul2009 03:07

Re: solve it plz
why u don`t solve it :(
really i don`t know how 2 solve it :(((((

All times are GMT +5.5. The time now is 17:56.