We appreciate your visit to Implement the program for this problem using a while loop construct and follow the code guidelines as described Task Write a program that will count. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!
Implement the program for this problem using a while loop construct, and follow the code guidelines as described:
**Task**: Write a program that will count down from 20 to 5 inclusive and display the count on the Console by performing the following steps:
1. Declare a variable of `int` data type with a name of your choice.
2. Assign the appropriate initial value to the variable that you declared.
3. Use a while loop construct that will loop based on the appropriate test condition involving the variable that you declared.
4. The body of the while loop should contain program statements that will perform the following:
- Display the text "variable name" followed by the value of the variable on the Console display.
- Create a Delay of 800 milliseconds using the KISS statement `msleep(800);`.
- Modify your variable as appropriate for counting down.
- Display the text "Count is smaller than 10" when the count is less than 10; otherwise, display the text "Count is large."
- Additionally, display the text "Count is now 16" when the count is exactly 16.
5. After the while loop is exited, display "Excellent" on the next line of the Console display.
**C Language Example Code**:
```c
#include
int main()
{
int counter;
counter = 20;
while (counter >= 5)
{
printf("counter is %d\n", counter);
if (counter < 10)
{
printf("Count is smaller than 10\n");
}
else
{
printf("Count is large\n");
}
if (counter == 16)
{
printf("Count is now 16\n");
}
counter = counter - 1;
msleep(800);
}
printf("Excellent\n");
return 0;
}
```
Ensure you include the necessary header file for `msleep()` if it's not a standard function in your environment.
int main()
{
int counter;
counter = 20;
while (counter >= 5)
{
printf("counter is %d\n", counter);
if (counter < 10)
{
printf("Count is smaller than 10\n");
}
else
{
printf("Count is large\n");
}
if (counter == 16)
{
printf("Count is now 16\n");
}
counter = counter - 1;
msleep(800);
}
printf("Excellent\n");
return 0;
}
```
Ensure you include the necessary header file for `msleep()` if it's not a standard function in your environment.