Jump to content
• Advertisement

# A Problem to Solve...

This topic is 3964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

OK, I have a problem and can't figure out a way around it, so maybe you guys can help me. I am trying to write a program that tracks my car's fuel usage. The features it requires are: - Average price of fuel - Average kilometres/litre - Average kilometres/tank - Calculate money owed (I drive people around a lot) - Some others... but they're the main ones. My problem is, I started off with a simple solution of just adding 'fill ups' in a log, finding the difference in odometer readings from one fill-up to the next, and then dividing that by however many litres I got when I filled up. Each fill-up contains the following information: - price of fuel - litres purchased - odemeter reading - date My problem is this: this model only works based on the assumption that I completely fill my car each time I buy petrol. If I just throw 10 bucks in, say, it will screw me up, because I will assume that the number of litres I bought with the $10 is the number of litres I have used since the last filling, if you understand me. So, I decided to ignore these little amounts, but then that screws me up when I fill-up anyway, because the program will calculate more kilometres (from the extra fuel provided by the little fills) than I really have done. So how do I get around it? Live with approximations - when I fill-up, state how many 8ths or 16ths, approximately, of the tank there was left? Is there a way around this I haven't seen? Oh, by the way, my car is a Daewoo Cielo from 864 BC, so it only has the gauge, no digital display telling me how much is in there. I'm thinking approximations won't really throw it off by much, considering my tank is only 40 litres. #### Share this post ##### Link to post ##### Share on other sites Advertisement Unless I'm missing something, there shouldn't be a problem. If you have: - price of fuel - litres purchased - odemeter reading You can keep track of total money spent on fuel, total litres of fuel spent, total kilometers driven fairly trivially. average kilometers per tank is simply a function of kilometers driven between the start of the tracking and the last refill, the total litres purchased, and the car's tank volume. #### Share this post ##### Link to post ##### Share on other sites What I'm saying is that when I refill, I'm assuming that the number of litres purchased is equal to the number of litres used since the last re-fill. So, if I do a partial re-fill, I won't know how many litres were used between the last re-fill and now. That's what I need to know. #### Share this post ##### Link to post ##### Share on other sites Mh fill up your tank and then check your handbook for the capacity from your tank. If you fill your tank every 2 or 3 tanks, you should be able to calculate your fueluseage really close to the reality. If this is not enough for you, you can build in a pressure gauge but i think it is a little bit uber #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by NickHighIQWhat I'm saying is that when I refill, I'm assuming that the number of litres purchased is equal to the number of litres used since the last re-fill. So, if I do a partial re-fill, I won't know how many litres were used between the last re-fill and now. That's what I need to know. Are you sure you need to know that? Since it wasn't one of the requirements that you listed. All the requirements that you listed can be calculated accurately without issue after you get a fair number of refills, as Sandman said. #### Share this post ##### Link to post ##### Share on other sites You could enter all refuelling visits, but set a flag when it's a complete fill up. That would then set a calibration point and update your average mileage. Partial refills would be ignored until the next full refill, whereupon they would be automatically taken into account. Or alternatively, on a partial fill up you could estimate as you suggested. So long as you base your next calibration point on real data rather than estimates, your margin of error should be well bounded. #### Share this post ##### Link to post ##### Share on other sites No, they can't be calculated, that's what I'm saying. It seems like they can, but they actually can't. I have 40L/40L in my tank. I use 30L. I now have 10L/40L. I buy$10 worth of petrol which on this particularly cheap and hypothetical day, happens to get me 10L of petrol - I now have 20L/40L. My odometer when I filled my tank last time (to 40L) was 0km. It's now 300km, which I write down. Now, there is absolutely no way of me knowing how much petrol that 300km was worth. If I filled it, however, I would have payed $30 and got 30L, which tells me that I must have used 30L over 300km. If I only got 10L of petrol, I have no way of knowing how many litres were used since the last fill, which leads to problems when I want to calculate averages because my program, as it stands, would assume I had used 10L over 300Km (which, as you can see, would become increasingly inaccurate as the amount of petrol bought decreases). Do you understand, yet? Maybe I am just so entrenched in this mindset that I can't see that you're correct, but at the moment, I'm still not convinced. My approximation solution says: I have a full tank. I drive 300km. I now have a quarter of a tank. I buy$10 worth of petrol which on this particularly cheap and hypothetical day, happens to get me 10L of petrol - I now have half a tank. Now, there is absolutely no way of me knowing exactly how much petrol that 300Km was worth. If I filled it, however, I would have payed $30 and got 30L, which tells me that I must have used 30L over 300Km. I know I have a 40L tank, and I can approximate fractions from the gauge. Is this the best solution possible other than to "build in a pressure gauge"? @Sandman: I had already thought of this idea, however, it still doesn't solve the problem. If, between to refills, I throw in an extra x litres, those extra litres will correspond with extra kilometres when it comes time to calculate the mileage again. The only way this would work is if you wrote down the mileage when you did a partial fill, and then again when the partial fill had run out (by approximating from the gauge) and then subtracting that from the mileage calculated at your next complete fill. This seems more complex than the other solution which doesn't involve flags. #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by NickHighIQ@Sandman: I had already thought of this idea, however, it still doesn't solve the problem. If, between to refills, I throw in an extra x litres, those extra litres will correspond with extra kilometres when it comes time to calculate the mileage again. That doesn't matter at all. You're still keeping track of the partial refills, you're just not taking them into account until you do a full refill. At a calibration point, i.e a refill, your total fuel used is the sum of all refills and partial fills to date, minus the size of the tank. Your total mileage is whatever your odometer says, minus whatever it said when you started tracking fuel usage. #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by NickHighIQNo, they can't be calculated, that's what I'm saying. It seems like they can, but they actually can't.I have 40L/40L in my tank. I use 30L. I now have 10L/40L. I buy$10 worth of petrol which on this particularly cheap and hypothetical day, happens to get me 10L of petrol - I now have 20L/40L. My odometer when I filled my tank last time (to 40L) was 0km. It's now 300km, which I write down. Now, there is absolutely no way of me knowing how much petrol that 300km was worth. If I filled it, however, I would have payed \$30 and got 30L, which tells me that I must have used 30L over 300km.

so write down 10L as well then when you do a full fill up you know you have burned X fuel for X KM. Just because your end calc. is 60L for 600KM when your car only holds 40L for an average of 400km a tank doesn't matter.

#### Share this post

##### Share on other sites
Oh! Now I understand what you're saying! OK, thanks Sandman and stonemetal! See, I told you it was probably just me only seeing it my way. OK, so when I do a full refill, I add each partial refill's litreage to the full refill's litreage, and the distance between each full refill divided by the aforementioned sum of litreages, I will get all the information I need! Eg.

Full: 30L (odometer 0km)
Partial: 5L
Partial: 10L
Partial: 7L
Full: 20L (odometer 420km)

So, I sum the litreages to get 42L, and then divide by the odometer's difference of 420km. OK! Too easy... off to my programming. Thanks, guys.

(P.S. I think I invented the word 'litreage'.)

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5
• Advertisement

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013555
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!