In: Computer Science
Write a program fragment (not a complete program) which will perform the following task:
The int variable m currently contains the number of minutes a basketball player played in their last game.
Use an IF statement(s) to print out an appropriate message based on the following:
If m is from 35 to 48, print the message "very tired"
If m is from 10 to 34, print the message "little tired"
If m is from 1 to 9, print the message "played at least"
If m is 0, print the message "bench warmer"
If m is not in the range from 0 to 48, print the message "invalid data"
Question : To write a program fragment.
Solution : Integer variable m contains the number of minutes a basketball player played in their last game.
Program Fragment in C language.
if(m==0)
{
printf("Bench warmer");
} else if(m>0 && m <=9)
{
printf(" played at least");
} else if(m>9 && m<=34)
{
printf("little tired");
} else if(m>34 && m<=48)
{
printf("very tired");
}else
{
printf("invalid data");
}
if(m==0) // Checking m equal to 0
{
printf("Bench");
} else if(m>0 && m <=9) // Checking m from 1 till 9
{
printf(" played least");
} else if(m>9 && m<=34) // checking m from 10 till 34
{
printf("little tired");
} else if(m>34 && m<=48) // Checking m from 35 till 48
{
printf("very tired");
}else // For every other value not in 0 to 48
{
printf("invalid data");
}