May 19, 2024, 01:33:35 AM

## News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!

## Speed - Distance Problem

Started by GWS, September 10, 2015, 02:55:11 AM

0 Members and 1 Guest are viewing this topic.

#### GWS

##### September 10, 2015, 02:55:11 AMLast Edit: September 10, 2015, 03:16:54 AM by GWS
Hi,

I don't know why I bothered with this, except it is a coding problem, and so needs solving just so it doesn't beat me ..

It comes from a very old bit of code in Creative Computing many moons ago ..

The problem as stated is:

A Car travelling at an average speed of C mph, can make a trip in H hours less than a Train
travelling at T mph. How long does the trip take by car ?
(The train speed includes lost time due to connections.  Thus C is always greater than T).

`' Speed and Time problem' A Car travelling at C mph, can make a trip in H hours less than a Train' travelling at T mph. How long does the trip take by car' The train speed includes lost time due to connections.  Thus C is always greater than T.openconsoledef C,T,H:intdef Error,EstCarTime,CarTime:floatdef YesNo:stringLabel AnotherclsPRINT: PRINT "TIME - SPEED - DISTANCE Exercise": PRINTPRINT string\$(32,"-")Label RedoC =INT(50*RND(1)) + 35 :' Car SpeedT =INT(30*RND(1)) + 15 :' Train SpeedH =INT(10*RND(1)) + 5 :' Time Difference' make sure the car speed is greater than the train speedif (C <= T) then goto RedoPRINTPRINT "A Car travelling at ",C,"mph can make a trip in"PRINT H,"hours less than a train travelling at ",T,"mph."PRINTINPUT "How long does the trip take by car ?  ",EstCarTimeCarTime = H * T /(C-T)Error = INT(ABS((CarTime-EstCarTime)*100/CarTime)+.5)PRINT:PRINT string\$(32,"-")' check if estimate is more than 5% out .. if (Error > 5) PRINT:PRINT "Sorry.  You were off by ",Error,"percent." PRINT PRINT "The correct answer is ",CarTime," hours." PRINTelse PRINT PRINT "Good Answer. You were only ",Error,"percent from" PRINT "the correct answer which is ",CarTime," hours." PRINTendifPRINT string\$(32,"-"):PRINT:PRINTINPUT "Would you like to try again (Y/N) ?  ",YesNoif (YesNO = "Y") | (YesNo = "y") then goto Anothercloseconsoleend' ........................' So how does the CarTime calculation come about ..'' The distance is unknown, but we start from Speed = Distance / Time' so car speed C = Distance / CarTime, and train speed T = Distance / TrainTime' Therefore CarTime = Distance / C, and TrainTime = Distance / T' Time saving H = TrainTime - CarTime' = Distance / T - Distance / C' so H * T = Distance - (Distance / C) * T' = Distance - CarTime * T' = C * CarTime - CarTime * T' = CarTime * (C - T)' hence, CarTime = H * T / (C - T)' Phew !! I'm geting too old for this stuff ..' ........................`

There, now I've got a headache ..

I reckon to use this program you've got to either be a good guesser, or you need to work it out for each set of values - not much fun ..  So I don't rate this very highly either for entertainment value or utility.
Still, I suppose all programs can't be exciting ..

Best wishes,

Graham

Tomorrow may be too late ..

#### aurelCB

##### September 11, 2015, 01:41:20 PM #1
Hi GWS
my main problem here is how to recalculate mph into kilometer per hour

#### GWS

##### September 12, 2015, 02:04:14 AM #2
Hi,

Ah, units conversion - always a problem

Try typing 'mph2kph' in Google. There are several online calculators to do the conversion.

By the way, the formula for the answer is in the code .. that should enable you to get close to the correct answer ..

all the best,

Graham

Tomorrow may be too late ..

#### aurelCB

##### September 12, 2015, 02:29:12 PM #3
i know sir...
it is just a joke