Borrar filtros
Borrar filtros

Write a script that...

3 visualizaciones (últimos 30 días)
Riri
Riri el 23 de En. de 2014
Respondida: ES el 23 de En. de 2014
This is one script that I have to write but i have no idea where to start. Any hints please?
The behavior of a bird (for the purpose of the exercise) is such that:   If it rains and the bird is hungry: the bird eats If it rains and that the bird is not hungry: the bird sleeps If it does not rain and the bird is hungry : the bird sings If it does not rain and the bird is not hungry: the bird sleeps If it does not rain or if the bird is not hungry : the bird is happy   Write a script that asks the user if the bird is hungry and if it rains. Depending on the user response, the script displays what the bird is doing and if he is happy or not. Use at least one logical operator
Thanks in advance

Respuesta aceptada

ES
ES el 23 de En. de 2014
bBirdIsHungry=input('Is the Bird Hungry? [1/0]');
bItRains=input('Does it Rain? [1/0]');%You can get yes or no if you want. I just kept it simple
if bBirdIsHungry&& bItRains %Logical operator
disp('the Bird Eats')
elseif ~bBirdIsHungry&& bItRains%Logical Operators
disp('the Bird Eats')
...
...%all other ifs and elses
...
end
An architectural suggestion is you can write a truth table depending on the two inputs and create output. That will simplify the equation(no of IFs and elses)

Más respuestas (0)

Categorías

Más información sobre MATLAB Support Package for USB Webcams en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by