write a function that will accpet three values. A user value, the smallest possi
ID: 3834495 • Letter: W
Question
write a function that will accpet three values. A user value, the smallest possible vlaue and the largest possile value. The function will then determine if that user value is between the smallest and largest value and return a boolean value. True if the user value is between the smallest and largest values. False when it is not. Ex. If I send in 20 , 5, 5 to the function it will return true. If I send 30, 5, 25 to the function then it will return false. IN the main program, you will need to test the returned value and print a message. " number is between smallest and largest values" or " number is not between smallest and largest values"
Explanation / Answer
Hi friend, you have not mentioned about any programming language.
Please try to mention all details.
I have implemented in Java
import java.util.Scanner;
public class Program {
public static boolean isUserValueInBetween(int u, int s, int l){
if(u > l && u < l)
return true;
else
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter smallest value: ");
int s = sc.nextInt();
System.out.print("Enter maximum value: ");
int l = sc.nextInt();
System.out.print("Enter your value: ");
int u = sc.nextInt();
if(isUserValueInBetween(u, s, l))
System.out.println("number is between smallest and largest value");
else
System.out.println("number is not between smallest and largest values");
sc.close();
}
}
/*
Sample run:
Enter smallest value: 5
Enter maximum value: 25
Enter your value: 30
number is not between smallest and largest values
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.