Question

In: Computer Science

Matlab code Here is the command that asks the user if he/she wants to play again:...

Matlab code

Here is the command that asks the user if he/she wants to play again:

playAgain = input(Would you like to play again? (y/n): ', 's');

Your task is to write a validation loop that only strings that start with a letter "y" or a letter "n", irrespective of cases, are considered to be valid input.

Solutions

Expert Solution

Program:

clc;

playAgain = input('Would you like to play again? (y/n): ', 's'); % Accept input


while(ne(playAgain,'Y') && ne(playAgain,'y') && ne(playAgain,'N') && ne(playAgain,'n')) % validate the input is correct or not
  
disp('Not a valid choice'); % it print not a valid choice
  
playAgain = input('Would you like to play again? (y/n): ', 's'); % Accept input

end

disp('Valid Input!') % print valid input

Output:


Related Solutions

Write a program where a user of this program will play a game in which he/she...
Write a program where a user of this program will play a game in which he/she needs to guess a target number, which is a number that the program has randomly picked in the range that the user chooses. The program will repeatedly prompt for the guessed number and provide a clue whether the guessed number is bigger or smaller than the target number, until the guessed number equals the target number.
Code in C ++ that asks the user for an integer and that prints whether or...
Code in C ++ that asks the user for an integer and that prints whether or not the number is divisible by three in the integers. If the number is not divisible by three, the program must write a message indicating what the remainder is obtained by dividing the number by three.
MATLAB Write a script which asks the user of the program to provide an initial horizontal...
MATLAB Write a script which asks the user of the program to provide an initial horizontal position, initial vertical position, initial velocity, and angle. Create a time vector spanning from zero seconds to 100 seconds incremented at 0.01 seconds. Call the function that you created in the previous problem to calculate the trajectory and velocities of the projectile. Find the maximum height of the projectile and the time at which it reaches that point. Write a neat sentence stating what...
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
Let’s say that a seller has a house she wants to sell for $150,000. She asks...
Let’s say that a seller has a house she wants to sell for $150,000. She asks the real estate agent to list it for sale at $160,000, but tells the agent not to entertain any bid below $140,000. An interested buyer, who can afford a mortgage at current rates if the total price is below $145,000 (his limit), looks at the house and likes it enough to put in an offer of $138,000. This situation could be characterized as: Group...
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer...
---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter...
---- Python CIMP 8A Code Lab 4 Write a program that asks the user to enter 5 test scores. The program will display a letter grade for each test score and an average grade for the test scores entered. The program will write the student name and average test score to a text file (“studentgrades.txt”). Three functions are needed for this program. def letter_grade( test_score) Test Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F...
1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money...
1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money from 0 to 99 cents. The program then calculates and displays the number of coins from each denomination: quarters (25 cents), dimes (10 cents), nickels (5 cents), and cents. For example, if the user enters 93, your program should display There are 3 quarters, 1 dimes, 1 nickels, and 3 cents in 93 cents Note: You must use integer division and modular division to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT