Question

Write a Guess My Number Game program. The program generates a random integer in a specified range, and the user (the player

Can someone upload a picture of the code in matlab

0 0
Add a comment Improve this question Transcribed image text
Answer #1
clear all
fprintf('\n welcome to guess my number game')
disp(' ')
a = input('\nPlease tell me you nice Name : ','s');
fprintf('\n\t Welcome to the game %s',a)
disp(' ');
m1 = 1;
while m1 == 1
    disp(' ');
    disp('Choose the level of playing:')
    disp('1) 1-10')
    disp('2) 1-100')
    disp(' ')
    o = input('enter the level you want to play: ');
    disp(' ')
    switch  o
        case 1,
            n = 10;
        case 2,
            n = 100;
        
    end
    
    b = randperm(n);
    index = randperm(length(b));
    r = b(index(1));
    
    m2 = 1;
    count = 0;
    while m2 == 1
        guess='r';
        while guess == 'r'
            guess = input('Input your guess: ','s');
        end
        guess = str2num(guess);
        if (guess == r);
            disp(' ')
            fprintf('Correct! My secret number was: %i\n',r)
            m2 = 2;
        elseif (guess > n);
            disp(' ')
            fprintf('Too high, please less than %i\n',n)
            disp(' ')
        elseif (g < 1);
            disp(' ')
            disp('Too low, please more than %i\n',n)
            disp(' ')
        elseif (guess > r);
            disp('Lower')
        else (guess < r);
            disp('Higher')
        end
        count = count+1;
    end
    disp(' ')
    fprintf('Guesses needed to find my secret number: %i\n',c)
    disp(' ')
    if (count == 1);
        disp('marvallous')
    elseif (count >= 2 && count < 0.5*n);
        disp('excellent')
    elseif (count == 0.5*n);
        disp('Avg')
    elseif (count > 0.5*n && count <= 0.8*n);
        disp('its very poor')
    else (count > 0.8*n);
        disp('better luck next time !')
    end
    disp(' ')
    p = input('will u wish to play again? (yes/no): ','s');
    if p == 'no'
        m1 = 2;
    end
    disp(' ')
    fprintf('Thank you very much %s\n',a)
end
Add a comment
Know the answer?
Add Answer to:
Can someone upload a picture of the code in matlab Write a "Guess My Number Game"...
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
  • 7.30 - Guess-the-Number Game (Project Name: GuessTheNumber) - Write an app that plays “Guess the Number”...

    7.30 - Guess-the-Number Game (Project Name: GuessTheNumber) - Write an app that plays “Guess the Number” as follows: Your app chooses the number to be guessed by selecting a random integer in the range 1 to 1000. The app displays the prompt "Guess a number between 1 and 1000: ". The player inputs a first guess. If the player’s guess is incorrect, your app should display Too high. Try again. or Too low. Try again. to help the player “zero...

  • In Java You’re going to make a Guess the Number game. The computer will "think" of...

    In Java You’re going to make a Guess the Number game. The computer will "think" of a secret number from 1 to 20 and ask the user to guess it. After each guess, the computer will tell the user whether the number is too high or too low. The user wins if they can guess the number within six tries. The program should look like this in the console, player input is in bold: Hello! What is your name? Abaddon...

  • Currently, the game allows players to play as many times as they wish. It does not...

    Currently, the game allows players to play as many times as they wish. It does not provide any feedback on how the players are doing, however. Modify the game so that it keeps track of the number of games played as well as the average number of guesses made per game. To implement this change, add the following list of global variables to the beginning of the script’s Main Script Logic section. Assign each variable an initial value of zero....

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

  • python Exercise: ex9.py Write a program that plays a number and you guess the number. The...

    python Exercise: ex9.py Write a program that plays a number and you guess the number. The program helps you with a response 1t the number you guessed is higher or lower than the mystery number. To generate a random number, we need to import some routines. guessing game. It generates a random mystery import random mysteryNumber random.randint (1, 100) The random.randint (1, 100) creates a random integer between 1 and 100. Here is a sample output: Let's play the guessing...

  • Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts...

    Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts the user for a guess. Use the pseudorandom number generator, the Random class. When the user guesses the correct number, say so, and display how many guesses the user required to guess correctly. Allow the user to play multiple times by asking the user if the user wants to continue playing.      Guess my number between 1 and 1000 => 500      Too high...

  • Please write a C# program that where a player will play a guessing game with the...

    Please write a C# program that where a player will play a guessing game with the range of 1-100. Each time the play guesses a number, and it is not correct the program should indicate if the number is more or less than what the player guessed. The play should be able to guess until the correct number has been guessed. If an invalid number is entered, such as: 1.24 (real number), or asd (string). The program should tell user...

  • Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

    Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...

  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

  • Write a program to play "guess my number". The program should generate a random number between...

    Write a program to play "guess my number". The program should generate a random number between 0 and 100 and then prompt the user to guess the number. If the user guesses incorrectly the program gives the user a hint using the words 'higher' or 'lower' (as shown in the sample output). It prints a message 'Yes - it is' if the guessed number is same as the random number generated. ANSWER IN C LANGUAGE. ====================== Sample Input / Output:...

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
ADVERTISEMENT