I have given instructions to write some code and i have to follow the comments giving and i get stuck and some point so can anyone tell me what i did wrong
* Returns the percent change from the original to the desired servings.
* The percent is expressed as a decimal. i.e.:
* 1 = 100%
* 0.5 = 50%
* 1.5 = 150%
* If either of the serving values is 0, a value of 1 serving is assumed.
* To calculate the number of servings, the following formula is used:
* Desired Servings =
* | Desired Servings / Original Servings | - 0.1 *
* (1 - | Original Servings / Desired Servings | ))
* where | x | is the absolute value of x
* original - number of servings the recipe was designed for
* desired - the number of servings wanted
* returns the % change that should apply to all of the ingredients.
double changeServings(int original, int desired)
//stops any division by 0
if (original == 0)
original = 1;
if (desired == 0)
desired = 1;
// get absolute value for | Original Serving / Desired Servings |
double rate = original / (double)desired;
if (rate < 0)
rate = -rate;
//modify -1 below to be your new calculated value.
return (rate - 0.1 * (1 - rate));