Как улучшить этот код? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Как улучшить этот код?

https://sololearn.com/compiler-playground/cgyM9FhLozq3/?ref=app Этот код должен отображать разные выводы в связи с переменной health

18th Dec 2023, 5:58 AM
Разин Ярослав Александрович
Разин Ярослав Александрович - avatar
2 Answers
+ 3
Your current code only handles the case when `health` is exactly 100. To make it more comprehensive, you might want to include additional cases and a default case for other health values. Additionally, consider adding break statements to exit the switch block after each case. Here's an improved version: ```c #include <stdio.h> int main() { int health = 100; switch (health) { case 100: printf("здоров как бык\n"); break; case 75: printf("хорошее здоровье\n"); break; case 50: printf("среднее здоровье\n"); break; case 25: printf("низкое здоровье\n"); break; default: printf("неизвестное состояние здоровья\n"); } return 0; } ``` This code now includes cases for various health values and a default case for any other value. Adjust the messages and conditions based on the specific health states you want to represent in your program.
18th Dec 2023, 6:31 AM
卂ㄚㄩ丂卄
卂ㄚㄩ丂卄 - avatar
+ 1
Thank u bro if you have <100 and >75 to
18th Dec 2023, 6:32 AM
Разин Ярослав Александрович
Разин Ярослав Александрович - avatar