Hello everyone, i'm having a huge problem with a simplistic program.
I'm very new to C# and i have to create a program that "allows a user to enter a trip distance. The output is the ticket price."
Distance ticket price
0-99 25.00
100-299 40.00
300-499 55.00
500 and farther 70.00
i've used arrays before but im not sure about the distance ranges (ex. 0-99, 100-299)
any help is very much appreciated
2 replies to this topic
#1
Posted 13 October 2011 - 05:31 AM
|
|
|
#2
Posted 13 October 2011 - 07:53 AM
Using boolean operators, this could be implemented very simply. (Pseudocode below)
Just continue with the pattern above until all ranges are tested. The last condition won't need a boolean AND, because you're only testing for values greater than or equal to 500.
if distance >= 0 AND distance < 100 ticket price = 25.00 else if distance >= 100 AND distance < 300 ticket price = 40.00 else if ... ...
Just continue with the pattern above until all ranges are tested. The last condition won't need a boolean AND, because you're only testing for values greater than or equal to 500.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#3
Posted 13 October 2011 - 09:53 AM
Thanks alot, worked out perfectly! :)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









