Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

# Write a function named guessme- The function should ask you to guess a.docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité

## Consultez-les par la suite

1 sur 2 Publicité

# Write a function named guessme- The function should ask you to guess a.docx

Write a function named guessme. The function should ask you to guess a number between 1 and 100. The function should allow three attempts to guess the number. It should respond with \'Guess a lower number\', \'Guess a higher number\',\'YOU WIN !!!\',or \'No, the number is __\' . Use rng(\'shuffle\') and randi() to generate the number.
Solution
% This is a guessing game
counter=0;
real_number=rand(1);
real_number=100*real_number;
number=ceil(real_number);
fprintf(\'I am thinking a number between 1 and 100.\ \');
guess=input(\'Guess a number: \');
while guess~= number
counter = counter + 1;
if guess>number
fprintf(\'Your guess is too high!\ \');
guess=input(\'Guess another number: \');
else
fprintf(\'Your guess is too low!\ \');
guess=input(\'Guess another number: \');
end
end
counter= counter + 1;
fprintf(\'Congratulations! You guessed the correct number in %g shots. \ \', counter);
.

Write a function named guessme. The function should ask you to guess a number between 1 and 100. The function should allow three attempts to guess the number. It should respond with \'Guess a lower number\', \'Guess a higher number\',\'YOU WIN !!!\',or \'No, the number is __\' . Use rng(\'shuffle\') and randi() to generate the number.
Solution
% This is a guessing game
counter=0;
real_number=rand(1);
real_number=100*real_number;
number=ceil(real_number);
fprintf(\'I am thinking a number between 1 and 100.\ \');
guess=input(\'Guess a number: \');
while guess~= number
counter = counter + 1;
if guess>number
fprintf(\'Your guess is too high!\ \');
guess=input(\'Guess another number: \');
else
fprintf(\'Your guess is too low!\ \');
guess=input(\'Guess another number: \');
end
end
counter= counter + 1;
fprintf(\'Congratulations! You guessed the correct number in %g shots. \ \', counter);
.

Publicité
Publicité

## Plus De Contenu Connexe

Publicité

### Write a function named guessme- The function should ask you to guess a.docx

1. 1. Write a function named guessme. The function should ask you to guess a number between 1 and 100. The function should allow three attempts to guess the number. It should respond with 'Guess a lower number', 'Guess a higher number','YOU WIN !!!',or 'No, the number is __' . Use rng('shuffle') and randi() to generate the number. Solution % This is a guessing game counter=0; real_number=rand(1); real_number=100*real_number; number=ceil(real_number); fprintf('I am thinking a number between 1 and 100. '); guess=input('Guess a number: '); while guess~= number counter = counter + 1; if guess>number fprintf('Your guess is too high! '); guess=input('Guess another number: '); else fprintf('Your guess is too low! '); guess=input('Guess another number: ');
2. 2. end end counter= counter + 1; fprintf('Congratulations! You guessed the correct number in %g shots. ', counter);