March 3rd, 2016, 02:55 AM  #1 
Newbie Joined: Mar 2016 From: The Netherlands Posts: 3 Thanks: 0  formula for counting calories?
Hi, I am creating an application which keeps track of how many calories you've eaten in a day. I'm mediocre at maths so I tried asking my maths teacher for help setting up the formula. this is what I've got so far: X (n+1) = Xn + ((y * z) * n) / 100 X = Calories for the day  n = Amount of types user has filled in a value to add to X  y = amount of grams eaten from food  z = calories/100g for the given food I've written down the amount of calories per food per 100g, that's why there's an /100 at the end. problem is this is not working and apparrantly my programming language doesn't allow me to fill in X(n+1) on the left side of the equals sign. Also I think the formula could be simplified but since it's an incorrect formula I can't get very far. Please tell me if you have any suggestions, I would really appreciate it (new to this forum so please forgive any mistakes I might make) Vidal 
March 3rd, 2016, 03:34 AM  #2 
Global Moderator Joined: Dec 2006 Posts: 20,617 Thanks: 2072 
What programming language are you using? Also, what do you mean by "keeps track of", given that you seem to have just one calculation? I don't understand your intended use of n, which appears 3 times with no explanation.

March 3rd, 2016, 03:38 AM  #3 
Senior Member Joined: Feb 2016 From: Australia Posts: 1,797 Thanks: 633 Math Focus: Yet to find out.  
March 3rd, 2016, 04:48 AM  #4 
Newbie Joined: Mar 2016 From: The Netherlands Posts: 3 Thanks: 0 
I am using Java. and N means the amount of times the user has added a value to X

March 3rd, 2016, 04:51 AM  #5 
Newbie Joined: Mar 2016 From: The Netherlands Posts: 3 Thanks: 0 
and with keeping track of I mean that I need a variable that can only increase and not change itself to a lower value. example: If you've eaten 2000 cal for the day, and eat a food that has 200 calories, I want the total number of calories to be 2200 and not to change to 200. 
March 3rd, 2016, 05:07 AM  #6  
Senior Member Joined: Feb 2016 From: Australia Posts: 1,797 Thanks: 633 Math Focus: Yet to find out.  Quote:
Provided you've initialised all your variables and are of the correct type (all int's by the looks of it) that wouldn't work (at least it wouldn't on C#). You'll need to just rearrange the formula you've got there so that you're only assigning a value to X.  
March 3rd, 2016, 05:18 AM  #7 
Senior Member Joined: Apr 2014 From: Glasgow Posts: 2,155 Thanks: 731 Math Focus: Physics, mathematical modelling, numerical and computational solutions 
Amount of calories to add = calories per 100g for item * mass of item consumed (g) / 100g New amount of calories = Old amount of calories + Amount of calories to add In symbols: $\displaystyle X_{n+1} = X_n + \frac{c_i m_i}{100}$ where $\displaystyle X_{n}$ = number of calories for $\displaystyle n$ items $\displaystyle c_i$ = calories per 100g for item $\displaystyle i$ $\displaystyle m_i$ = mass of item $\displaystyle i$ consumed (g) You can either add the above function to the end of the function where the user adds each item of food consumed, or alternatively, you can have an update function in the box displaying the total calories eaten and whenever an item is changed in the list of items consumed, you calla function that does the whole sum: $\displaystyle X_n = \sum_{i=1}^n \frac{c_i m_i}{100}$ Basically you just loop over all the items and work out the $\displaystyle \frac{c_i m_i}{100}$ term for each one. Last edited by Benit13; March 3rd, 2016 at 05:21 AM. 

Tags 
calories, counting, formula 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Counting Theorem and Burnside's Formula  MommaOrtiz  Abstract Algebra  0  November 11th, 2010 11:31 AM 