Question

In: Computer Science

Write a program fragment (not a complete program) which will perform the following task: The int...

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"

Solutions

Expert Solution

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");
    }

Related Solutions

In C: Write a complete program that performs the following task: Ask the user for the...
In C: Write a complete program that performs the following task: Ask the user for the number of sequences to display. For each sequence, Ask the user for a starting value Print out the value and double it (multiply by 2). Continue printing and doubling (all on the same line, separated by one space each) as long as the current number is less than 1000, or until 8 numbers have been printed on the line. You may assume that the...
You will write a Java Application program to perform the task of generating a calendar for...
You will write a Java Application program to perform the task of generating a calendar for the year 2020. You are required to modularize your code, i.e. break your code into different modules for different tasks in the calendar and use method calls to execute the different modules in your program. Your required to use arrays, ArrayList, methods, classes, inheritance, control structures like "if else", switch, compound expressions, etc. where applicable in your program. Your program should be interactive and...
Please design a PLC program to perform the following task: An LED will be on when...
Please design a PLC program to perform the following task: An LED will be on when it’s activated by an NO push button for an accumulated 6 seconds. In other words, the push button can be on and off, but when it’s accumulated for six seconds, the LED will be on. After six seconds, the LED will be on for four seconds and is then reset itself for another cycle. Post LogixPro image of this programming Cascading timer Assume the...
Write a C++ program fragment which illustrates the throwing and catching of a logic_error while performing...
Write a C++ program fragment which illustrates the throwing and catching of a logic_error while performing a division in the case of division by zero.
1. For each of the following, write C++ statements that perform the specified task. Assume that...
1. For each of the following, write C++ statements that perform the specified task. Assume that unsigned integers are stored in four bytes and that the starting address of the built-in array is at location 1002500 in memory. Declare an unsigned int built-in array values with five elements initialized to the even integers from 2 to 10. Assume that the constant size has been defined as 5. Declare a pointer vPtr that points to an object of type unsigned int....
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
Write a method which is passed A[], which is an array of int, and an int...
Write a method which is passed A[], which is an array of int, and an int passingScore. The method returns the number of items in A[] which are greater than or equal to passingScore. Write a method which is passed an array of int A[]. The method returns true if A[] is the same backwards and forwards. Write a method same( ), which is passed two arrays of int. The method returns true if the two arrays contain exactly the...
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
write a program to perform the following in C Your program should prompt the user to...
write a program to perform the following in C Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings. After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case. Once the list is in alphabetical order, the list should be output to the console in order. The program should execute...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT