TurkeyTimer - need explanations

Hello,

Got a bit stacked at Turkey Timer.

Here’s the initial code

void showCookTimeForTurkey (int pounds)

{
int necessaryMinutes = 15 + 15 * pounds;
printf(“Cook for %d minutes.\n”, necessaryMinutes);

}

int main(int argc, const char * argv[])

{

int totalWeight = 10;
int gibletsWeight = 1;
int turkeyWeight = totalWeight - gibletsWeight;
showCookTimeForTurkey (turkeyWeight);

return 0;

}

I DO understand that the program starts executing from MAIN.

So the machine comes across to the showCookTimeForTurkey function.

After that it comes to void that above the MAIN.

the question is - how it knows that the pound = 9.

As I understand, we calculate int turkeyWeight = totalWeight - gibletsWeight;
but in the void above MAIN there’s no mentioning any int turkeyWeight

Thanks for the explanation

Cheers,
D

[quote][code]void showCookTimeForTurkey (int pounds)
{
int necessaryMinutes = 15 + 15 * pounds;
printf (“Cook for %d minutes.\n”, necessaryMinutes);
}

int main (int argc, const char * argv[])
{

showCookTimeForTurkey (turkeyWeight);

}
[/code][/quote]
The value of the argument (turkeyWeight) you call the function with is passed to the function under the name pounds.

Hi i want to understand how does the answer 150 minutes come across?

As this says " int necessaryMinutes = 15 + 15 * pounds; " (does ’ * ’ mean multiplication ?, even if this does means multiply so that would be 15 + 15 x 9(turkey weight) which does not sum upto 150 )

int totalWeight = 10;
int gibletsWeight = 1;
int turkeyWeight = totalWeight - gibletsWeight;
showCookTimeForTurkey(turkeyWeight);

this is clear how the answer comes to 9 for the turkey weight but i am confused how the answer sums up to 150mins?

some help would be appreciated.

the code is below.

Thanks
#include <stdio.h>

void showCookTimeForTurkey (int pounds)
{

int necessaryMinutes = 15 + 15 * pounds;
printf("cook for %d minutes.\n", necessaryMinutes);

}

int main(int argc, const char * argv[]) {

int totalWeight = 10;
int gibletsWeight = 1;
int turkeyWeight = totalWeight - gibletsWeight;
showCookTimeForTurkey(turkeyWeight);
return 0;

}

15 + 15 x 9 = 15 x (1 + 9) = 15 x 10 = 150

15 + 15 x 9 = 15 x (1 + 9) = 15 x 10 = 150[/quote]

Thank you for the reply.

I did not understand that well enough.

From what i understand that turkey weight = 9 after deducting, “15 + 15 * pounds” sums to 150 as 15 x 9 = 135 + 15 = 150,

in a case it would have been int nesscary minutes = (15 + 15) x 9 the answer would have been different as in this case it sums upto 30 and then multiplies by 9.

Have i understood this correctly?

[quote]in a case it would have been int nesscary minutes = (15 + 15) x 9 the answer would have been different as in this case it sums upto 30 and then multiplies by 9.

Have i understood this correctly?
[/quote]
Yes.

However, because ‘*’ operator has higher precedence, the above statement can also be written as:

int necessaryMinutes = 15 + (15 * pounds);

But not as:

int necessaryMinutes = (15 + 15) * pounds;

Thank You

[quote=“ibex10”][quote]in a case it would have been int nesscary minutes = (15 + 15) x 9 the answer would have been different as in this case it sums upto 30 and then multiplies by 9.

Have i understood this correctly?
[/quote]
Yes.

However, because ‘*’ operator has higher precedence, the above statement can also be written as:

int necessaryMinutes = 15 + (15 * pounds);

But not as:

int necessaryMinutes = (15 + 15) * pounds;