HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>Time to work, a letter from the boss!</p>
1 <p>Time to work, a letter from the boss!</p>
2 <p><b>Second task</b>: you need to improve the program “Can I Eat More?”. Input data is the same:</p>
2 <p><b>Second task</b>: you need to improve the program “Can I Eat More?”. Input data is the same:</p>
3 <ul><li>daily amount of food, in the variable dayLimit;</li>
3 <ul><li>daily amount of food, in the variable dayLimit;</li>
4 <li>weight of food eaten today, in the variable foodInGrams.</li>
4 <li>weight of food eaten today, in the variable foodInGrams.</li>
5 </ul><p>But the logic needs to be changed. The program should show how many grams of food can still be eaten today. If the amount of eaten food is greater than the daily amount, then the program should show zero.</p>
5 </ul><p>But the logic needs to be changed. The program should show how many grams of food can still be eaten today. If the amount of eaten food is greater than the daily amount, then the program should show zero.</p>
6 <p>First, let’s think over the solution algorithm:</p>
6 <p>First, let’s think over the solution algorithm:</p>
7 <ol><li>let’s set up a new variable to store the amount of food that can still be eaten;</li>
7 <ol><li>let’s set up a new variable to store the amount of food that can still be eaten;</li>
8 <li>let’s check if the amount of eaten food is less than the norm;</li>
8 <li>let’s check if the amount of eaten food is less than the norm;</li>
9 <li>if so, we subtract from the norm the amount of eaten food, and save the result in the new variable;</li>
9 <li>if so, we subtract from the norm the amount of eaten food, and save the result in the new variable;</li>
10 <li>if not, we write a zero in the new variable;</li>
10 <li>if not, we write a zero in the new variable;</li>
11 <li>log a beautiful informative message.</li>
11 <li>log a beautiful informative message.</li>
12 </ol><p>As you can see, inside the conditions, you can and you should perform operations with variables, and not just log messages.</p>
12 </ol><p>As you can see, inside the conditions, you can and you should perform operations with variables, and not just log messages.</p>