USE MATLAB Write a program in Matlab that would continuously ask the user for an input between...

90.2K

Verified Solution

Question

Advance Math


USE MATLAB

Write a program in Matlab that would continuously ask the userfor an input between 1 and 6, which would represent the result ofrolling a die. The program would then generate a random integerbetween 1 and 6 and compare its value to the value entered byuser.
If the user’s die is larger, it should display, “Mahahanap mona ang forever mo. Sana all!”
If the user’s die is smaller, it should display, “Gising nafriend, di ka niya mahal!”
If the results are the same, it should display, “Move on naghorl”.
The program should ask if the user wants to play another game(to be answered by either ‘Y’ or ‘N’). If the user answers ‘Y’, thegame continues. If the user answers ‘N’, the game ends and it willdisplay, “Mabuti naman at natauhan ka na!”.
The program should have a main script named lovedicegame.m andcalls on the following functions:
a. A function readdice.m to prompt the user and read in theinteger input.
b. A function genrandomdice.m to generate a random integerbetween 1 and 6.
c. A function comparedice.m to compare the input and thegenerated integer and display the results.
Sample run:
>> lovedicegame
>> Do you want to play the lovedice game (Y/N)? Y
>> Enter your dice: 5
>> My dice result: 6
>> Gising na friend, di ka niya mahal!
>> Play again (Y/N)? Y
>> Enter your dice: 3
>> My dice result: 1
>> Mahahanap mo na ang forever mo. Sana all!
>> Play again (Y/N)? Y
>> Enter your dice: 2
>> My dice result: 2
>> Move on na ghorl!
>> Play again? N
>> Mabuti naman at natauhan ka na!
Run the game for values:
3?,1,?4?,1?,6

Answer & Explanation Solved by verified expert
4.1 Ratings (843 Votes)
Here is the code for lovedicegamem clc clear all if inputDo you want to play lovedice game YN s N return end out Y while out Y nuser readdice User input ndice genrandomdice Dice number comparedicenuser ndice out inputPlay again YN s if out N dispMabuti naman at natauhan ka na end end First we ask the player if    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students