Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Long Distance Call Program - Please HELP
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hopping




PostPosted: Sun Mar 25, 2012 1:31 pm   Post subject: Long Distance Call Program - Please HELP

What is it you are trying to achieve?
I'm trying to write this program that takes input from the user to calculate the cost of his/her long-distance call. I take input such as Day of the Week, length of call, when the call started, etc...There are also specific rates for the calls:

- Between 8:00 AM & 6:00 PM, Monday through Friday, is billed at a rate of $0.50 per minute.
- Before 8:00 AM or after 6:00 PM, Monday through Friday, is charged at a rate of $0.40 per minute.
- Started on a Saturday or Sunday is charged at a rate of $0.25 per minute.


What is the problem you are having?
Saturday & Sunday is fine. No problem there. I have made the program and the calculations are fine. However, one thing that I did not take into account is that from Monday to Friday, what if the call starts in one rate period and ends in another. The calculation will need to calculate both rates and add them together. For example, on Tuesday, if someone starts the call at 5:50 PM and talks for 20 mins, that means from 5:50 to 6, it's charging $0.40 per min and after that until 6:10 it's charging $0.50. I've made it so that only the starttime rate is calculated, which is not right as it needs to be able to do cross-rate calculations.


Describe what you have tried to solve this problem
I have no clue what to do. Tried to do it on paper first but still, my brain isn't working. Please help


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This is my program without the cross-rate calculations. It works but can't do it if the user call goes from one rate to another.

Turing:


var day:string
var start,long:int
var cost:real

put "Please enter the day of the week you called (first letter capitalized)..."
get day
put ""
put "Please enter the time you started the call in military (24hr) form without the colon."
put "For example, 8:30 PM = 2030, 12:30 AM = 030, 3:15 AM = 315, 11:45 PM = 2345, etc..."
get start
put ""
put "Please enter how long you talked in minutes..."
get long
put ""

if (day="Monday" or day="Tuesday" or day="Wednesday" or day="Thursday" or day="Friday") and (start>=800 and start<=1759) then
    cost:=long*0.50
    put "The cost of your long-distance call is $", cost:0:2, "."
else
    if (day="Monday" or day="Tuesday" or day="Wednesday" or day="Thursday" or day="Friday") and (start<800 or start>1759) then
        cost:=long*0.40
        put "The cost of your long-distance call is $", cost:0:2, "."
    else
        cost:=long*0.25
        put "The cost of your long-distance call is $", cost:0:2, "."
    end if
end if



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Sun Mar 25, 2012 4:57 pm   Post subject: Re: Long Distance Call Program Help

Well, here's how I would approach it.
Say we start a call on Sunday at 23:00 and talk for 12 hours (720 minutes). This call is spread out over all three calling periods. We spend 1 hour talking on the weekend, 8 hours talking between 0:00 and 8:00 on Monday and 3 hours talking from 8:00 to 11:00 on Monday. So I would first find how long I spent on Sunday and work out the cost (in this case its 60 * $0.25 = $15). Next I find the cost for Monday morning (8 * 60 * $0.4 = $192). Finally, I find the cost for the final 3 hours (3 * 60 * $0.5 = $90). Basically, we separate the call into sections and calculate the cost of each section one at a time.

So how do we get write a program to do this?
Well, we will need a loop.

1 - Find the time of a call from the starting time until the end of the current billing period or the current day (be careful, there are 60 minutes between 0 and 100)
2 - Find the minimum of the call duration and the value found in 1 (in case the call doesn't last the whole billing period)
3 - Increase the bill by the product of the value found in 2 and the rate of the current billing period
4 - subtract the value found in 1 from the duration (we have charged these minutes)
5 - Change the starting time of the call to be the end of the billing period we just charged (ex: we charge from 1400 to 1800 on Monday, and set the starting time of the call to 1800 afterwards)
6 - Change the day if necessary
7 - If the call duration is still positive we have not charged the full call and must start back at step 1.

This will require a couple if statements and perhaps some careful logic for the conditions on the if statement.
Zren




PostPosted: Sun Mar 25, 2012 5:10 pm   Post subject: Re: Long Distance Call Program Help

Also: Expect your users to be idiots. Do not assume the person will capitalize the word.

"M" not= "m" (does not equal)

You're code will take the lowercase "monday" or any invalid entry like "fasdf" and assume the person meant a day on the weekend.

To prevent the mishaps with casing, make sure both strings are in the same case when comparing them.

Turing:

put "nargles" = "Nargles" % false
put Str.Lower("NARglES") = Str.Lower("nARGLEs") % true


You *should* also validate that the entered string depicts a day of the week, but that's probably overkill.
Tony




PostPosted: Mon Mar 26, 2012 1:50 am   Post subject: Re: Long Distance Call Program Help

Dreadnought @ Sun Mar 25, 2012 4:57 pm wrote:
Say we start a call on Sunday at 23:00 and talk for 12 hours (720 minutes). This call is spread out over all three calling periods.

Of course this doesn't take into account things like Daylight Savings Time Laughing

Seriously though. Time is hard. Time is really really hard.
http://www.wired.com/wiredenterprise/2012/03/azure-leap-year-bug/ wrote:

Microsoft has confirmed that Wednesday?s Windows Azure outage that left some customers in the dark for more than 12 hours was the result of a software bug triggered by the Feb. 29 leap-year date that prevented systems from calculating the correct time.

http://edition.cnn.com/2009/TECH/01/01/zune.player.failures/ wrote:

Many Zune owners successfully revived their failed music players Thursday morning, while others were still unable to overcome a leap year-related glitch that caused thousands of the devices to simultaneously stop working on New Year's Eve.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DemonWasp




PostPosted: Mon Mar 26, 2012 1:54 am   Post subject: RE:Long Distance Call Program - Please HELP

Really, really hard: http://www.defenseindustrydaily.com/f22-squadron-shot-down-by-the-international-date-line-03087/
mirhagk




PostPosted: Mon Mar 26, 2012 7:58 am   Post subject: RE:Long Distance Call Program - Please HELP

Really, really, really hard: http://www.dailymail.co.uk/sciencetech/article-1325561/iPhone-4-clock-bug-makes-owners-late-work-alarm-setting-does-update.html

Also remember Y2K? Abbreviating 4 digit years to 2 digits can't go wrong. A lot of money was spent in 98-99 correcting those bugs. The fix for some programs (like a healthcare data entry program my mom uses) was to wrap the year around and say anything before x is actually after 99 (in the case of my mom's program it was 10, so in 2010 the Y2K problem happened to her)
sandranil




PostPosted: Tue May 05, 2015 10:56 am   Post subject: Re: Long Distance Call Program Help

Dreadnought @ Sun Mar 25, 2012 4:57 pm wrote:
Well, here's how I would approach it.
Say we start a call on Sunday at 23:00 and talk for 12 hours (720 minutes). This call is spread out over all three calling periods. We spend 1 hour talking on the weekend, 8 hours talking between 0:00 and 8:00 on Monday and 3 hours talking from 8:00 to 11:00 on Monday. So I would first find how long I spent on Sunday and work out the cost (in this case its 60 * $0.25 = $15). Next I find the cost for Monday morning (8 * 60 * $0.4 = $192). Finally, I find the cost for the final 3 hours (3 * 60 * $0.5 = $90). Basically, we separate the call into sections and calculate the cost of each section one at a time.

So how do we get write a program to do this?
Well, we will need a loop.

1 - Find the time of a call from the starting time until the end of the current billing period or the current day (be careful, there are 60 minutes between 0 and 100)
2 - Find the minimum of the call duration and the value found in 1 (in case the call doesn't last the whole billing period)
3 - Increase the bill by the product of the value found in 2 and the rate of the current billing period
4 - subtract the value found in 1 from the duration (we have charged these minutes)
5 - Change the starting time of the call to be the end of the billing period we just charged (ex: we charge from 1400 to 1800 on Monday, and set the starting time of the call to 1800 afterwards)
6 - Change the day if necessary
7 - If the call duration is still positive we have not charged the full call and must start back at step 1.

This will require a couple if statements and perhaps some careful logic for the conditions on the if statement.



I was wondering how one would change the day
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: