Shal Lango

Ranch Hand

Posts: 31

posted 9 months ago

Newton’s Law of Cooling states that when a hot liquid is placed in a cool

room, each minute the decrease in the temperature is approximately proportional

to the difference between the liquid’s temperature and the room’s temperature.

That is, there is a constant k such that each minute the temperature loss is

k # (liquids temperature - rooms temperature). Suppose a cup of 212°F coffee is

placed in a 70°F room and that k = .079. Determine the number of minutes required

for the coffee to cool to below 150°F.

I'm not completely sure about my math here. I haven't fully coded yet, I just want to get the math right first.

room, each minute the decrease in the temperature is approximately proportional

to the difference between the liquid’s temperature and the room’s temperature.

That is, there is a constant k such that each minute the temperature loss is

k # (liquids temperature - rooms temperature). Suppose a cup of 212°F coffee is

placed in a 70°F room and that k = .079. Determine the number of minutes required

for the coffee to cool to below 150°F.

I'm not completely sure about my math here. I haven't fully coded yet, I just want to get the math right first.

Shal Lango

Ranch Hand

Posts: 31

posted 9 months ago

I meant minutes += 1 on line 9

Shal Lango wrote:Newton’s Law of Cooling states that when a hot liquid is placed in a cool

room, each minute the decrease in the temperature is approximately proportional

to the difference between the liquid’s temperature and the room’s temperature.

That is, there is a constant k such that each minute the temperature loss is

k # (liquids temperature - rooms temperature). Suppose a cup of 212°F coffee is

placed in a 70°F room and that k = .079. Determine the number of minutes required

for the coffee to cool to below 150°F.

I'm not completely sure about my math here. I haven't fully coded yet, I just want to get the math right first.

I meant minutes += 1 on line 9

Shal Lango

Ranch Hand

Posts: 31

posted 9 months ago

Like this?

k = 0.79;

room = 70;

cup = 212;

tempLoss = 0;

minutes = 0;

while (cup <= 212 & cup >= 150) {

tempLoss = k*(cup - room);

tempLoss = cup

minutes += 0;

}

Liutauras Vilda wrote:Your code won't achieve what the formula says.

One of the reasons are, that you never update liquid's (which is in a cup I pressume) temperature.

Like this?

k = 0.79;

room = 70;

cup = 212;

tempLoss = 0;

minutes = 0;

while (cup <= 212 & cup >= 150) {

tempLoss = k*(cup - room);

tempLoss = cup

minutes += 0;

}

Shal Lango

Ranch Hand

Posts: 31

Shal Lango

Ranch Hand

Posts: 31

Shal Lango

Ranch Hand

Posts: 31

Campbell Ritchie

Marshal

Posts: 56576

172

posted 9 months ago

What types are the three numbers? You can get incorrect results if you use the wrong types.

You have written 0.79 when the question says 0.079.

Why have you written the bit about <= 212? Does that do anything useful?

There is probably a method using logarithms which is simpler but you are probably being taught how to write a loop.

You have written 0.79 when the question says 0.079.

Why have you written the bit about <= 212? Does that do anything useful?

There is probably a method using logarithms which is simpler but you are probably being taught how to write a loop.

Don't get me started about those stupid light bulbs. |