Question

In: Computer Science

For C++ IDE Write an C++ to check if a number is falling within the range...

For C++ IDE

Write an C++ to check if a number is falling within the range j...k (inclusive). Ask the user to enter both ranges j, K and the number num you want to check. Output the suitable message based on the situation Within the range Outside the range Always prompt the user to enter a value using a suitable message.

For example (multiple runs)

Enter J - beginning of the range: 3

Enter K – end of the range: 15

Enter the value you want to check: 6

6 is within the range 3 to 15

Enter J - beginning of the range: 6

Enter K – end of the range: 15

Enter the value you want to check: 6

6 is within the range 6 to 15

Enter J - beginning of the range: 6

Enter K – end of the range: 15

Enter the value you want to check: 16

16 is outside the range 6 to 15

Solutions

Expert Solution

C++ code:

#include <iostream>
using namespace std;
int main()
{
//initializing j k and num
int j,k,num;
//asking for j
cout<<"Enter J - beginning of the range: ";
//accepting it
cin>>j;
//asking for K
cout<<"Enter K – end of the range: ";
//accepting it
cin>>k;
//asking for num
cout<<"Enter the value you want to check: ";
//accepting it
cin>>num;
//checking if num is within the range
if(num>=j && num<=k)
//printing it is within the range
cout<<num<<" is within the range "<<j<<" to "<<k<<endl;
else
//printing it is outside the range
cout<<num<<" is outside the range "<<j<<" to "<<k<<endl;
return 0;
}


Screenshot:


Input and Output:


Related Solutions

Write a program that prompts the user to enter a number within the range of 1...
Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive • The program then generates a random number using the random class: o If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number o If the users guess matches the random number tell them they win! o If the users guess does not match the random number tell them they...
Write a program that prompts the user to enter a number within the range of 1...
Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive • The program then generates a random number using the random class: o If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number o If the users guess matches the random number tell them they win! o If the users guess does not match the random number tell them they...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot : raw data, delay data (int) Purpose: Delay Block (**Using Class**) Input : u(t) Output : o(t)=u(t-h) sample time=0.02 Delay (h) = 0.4
In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
The amount of snowfall falling in a certain mountain range is normally distributed with a mean...
The amount of snowfall falling in a certain mountain range is normally distributed with a mean of 84 inches and a standard deviation of 10 inches. What is the probability that the mean annual snowfall during 25 randomly picked years will exceed 86.8 inches? Round your answer to four decimal places. A.0.4192 B.0.0808 C.0.5808 D.0.0026
C Programming Question: Q) Write a C - program to check whether a given graph is...
C Programming Question: Q) Write a C - program to check whether a given graph is Bipartite using Breadth-first search (adjacency list) Do take your time but please do post full code and also please do it in C.
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT