Question

Modular program mathlab: Write a program in Matlab that would continuously ask the user for an...

Modular program mathlab:

Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user.

If the user’s die is larger, it should display, “You got it”

If the user’s die is smaller, it should display, “Nice try”

If the results are the same, it should display, “Awesome”.

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’, the game continues. If the user answers ‘N’, the game ends and it will display, “Thank you for playing”.

The program should have a main script named rollingdie.m and calls on the following functions:

  1. A function inputdie.m to prompt the user and read in the integer input.
  2. A function randomizer.m to generate a random integer between 1 and 6.
  3. A function compdice.m to compare the input and the generated integer and display the results.

All in all a total of 4 script with the mainscript(rollingdie.m) and subscript (inputdie.m,randomizer.m,compdice.m)

Sample run:

>> rollingdie

>> Do you want to play the lovedice game (Y/N)? Y

>> Enter your dice: 4

>> My dice result: 6

>> Nice try

>> Play again (Y/N)? Y

>> Enter your dice: 5

>> My dice result: 3

>> You got it

>> Play again (Y/N)? Y

>> Enter your dice: 3

>> My dice result: 3

>> Awesome

>> Play again? N

>> Thank you for playing

0 0
Add a comment Improve this question Transcribed image text
Answer #1

%main script
play=input('Do you want to play the lovedice game (Y/N)? ','s');
while strcmp(play,'Y')
op=inputdie();
d = randomizer();
fprintf('My dice result: %d\n',d)
compdice(op,d);
play=input('Play again (Y/N)? ','s');
end
disp('Thank you for playing')

%functions
function op = inputdie()
op=input('Enter your dice: ');
end

function d = randomizer()
d=randi(6);
end

function compdice(ip,die)
if ip>die
disp('You got it');
elseif ip<die
disp('Nice try');
else
disp('Awesome')
end
end

Add a comment
Know the answer?
Add Answer to:
Modular program mathlab: Write a program in Matlab that would continuously ask the user for an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Craps

    Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...

  • Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game....

    Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game. It is played through dice. Rule for scoring The player who rolls higher number gets one point. If both players roll the same number, it is considered a draw and no one gets a point. Dice Specification There are two kinds of dice: normal die, represented by Die class. loaded die, represented by the loadedDie class. Classes Die class Die class has a member...

  • Write a script in MATLAB that prompts the user to do a, b, & c. a.)script...

    Write a script in MATLAB that prompts the user to do a, b, & c. a.)script that prompts the user to enter the day of the week using the input function. If the information the user enters is equal to “Saturday” or “Sunday”, display “have a nice weekend” in the Command Window. Otherwise, display “Good luck in your class lectures and your studies.” b.)script that prompts the user to input the following array by providing an example in the prompt:...

  • Specification Write a program that allows the user to play number guessing games. Playing a Guessing...

    Specification Write a program that allows the user to play number guessing games. Playing a Guessing Game Use rand() function from the Standard C Library to generate a random number between 1 and 100 (inclusive). Prompt the user to enter a guess. Loop until the user guesses the random number or enters a sentinel value (-1) to give up. Print an error message if the user enters a number that is not between 1 and 100. Print an error message...

  • WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a...

    WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a lot. Pig Dice Game Pig is a simple two player dice game, played with one die. The first player to reach or surpass 50 is the winner. Each player takes a turn rolling the dice. They add to the pot with each roll, having to decide to roll again and increase the pot, or cash out. The risk being they could lose the amount...

  • In the game of Lucky Sevens, the player rolls a pair of dice. If the dots...

    In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are many ways to win: (1, 6), (2, 5), and soon. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people's eyes glaze over at the first...

  • USE PYTHON ONLY Please write a Python program to let you or the user play the...

    USE PYTHON ONLY Please write a Python program to let you or the user play the game of rolling 2 dice and win/lose money. Initially, you have 100 dollars in your account, and the dealer also has 100 dollars in his/her account. You would be asked to enter a bet to start the game. If your bet is zero, the game would be stopped immediately. Otherwise, dealer would roll 2 dice and get a number from ( random.randint(1, 6) +...

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

    C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...

  • **IN JAVA** Make a Game -Game Strategy The program and the user alternate turns, picking up...

    **IN JAVA** Make a Game -Game Strategy The program and the user alternate turns, picking up one, two, or three straws on each turn. The program goes first. The player to pick up the last straw loses. -Game process Your program should start by generating and displaying a random integer (which represents the number of straws) between 10 and 20 inclusive. If this number is 1 more than a multiple of 4, add 1. For example, if the random integer...

  • This needs to be done using c++ No vectors or arrays can be used since we...

    This needs to be done using c++ No vectors or arrays can be used since we haven't learned them yet! Write a program that simulates a slot machine. The slot machine should have the following characteristics: - 3 view windows to display items on a wheel. Typically, these are cherries, bars, etc. - each wheel will randomly select a number 1-7. - the user will be charged 5 tokens to spin the wheels Winning combinations will be as follows: -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT