111k views
2 votes
Write a MATLAB program (a3q3.m) that prompts the user to enter a number in the range 0 to 25. If the number entered is less than 0 or greater than 25, output an out-of-range message and terminate. If the number entered is in the required range, proceed to test the number using the testLucky function written in the last question. Inform the user if the number entered is lucky or not lucky. Three example runs of the program are shown below, with user input underlined. Your program should create output exactly as shown below for the three values entered. Of course, your program should accept any number as input. Enter an number in the range o to 25: 22 You win! 22 is a lucky number Enter an number in the range o to 25: 10 Sorry! 10 is not a lucky number Enter an number in the range o to 25: 33 Number out of range! >>

User Norma
by
8.2k points

1 Answer

6 votes

Final answer:

To write a MATLAB program that prompts the user to enter a number in the range 0 to 25 and checks if the number is lucky or not, you can use the provided code. The program first prompts the user for input, then verifies if the number is in the required range. If it is, the program calls the testLucky function to determine if the number is lucky or not.

Step-by-step explanation:

To write a MATLAB program that prompts the user to enter a number in the range 0 to 25, you can use the following code:

# Prompt user for input
num = input('Enter a number in the range 0 to 25: ');

# Check if number is out of range
if num < 0 || num > 25
disp('Number out of range!');
else
# Call testLucky function
lucky = testLucky(num);

# Check if number is lucky
if lucky
disp('You win! '+num2str(num)+' is a lucky number');
else
disp('Sorry! '+num2str(num)+' is not a lucky number');
end
end

This program first prompts the user to enter a number using the input function. It then checks if the number is out of the required range using an if condition. If the number is in the range, it calls the testLucky function and checks if the number is lucky or not.

User Argentpepper
by
8.4k points