Question & Answer: I am trying to code a program for a glitter bomb by MATLAB and by using if and while conditions :…..

I am trying to code a program for a  glitter bomb by MATLAB and by using if and while conditions :

here are some detals :

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: I am trying to code a program for a glitter bomb by MATLAB and by using if and while conditions :…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

you’ve decided to give me a thank-you gift of a glitter bomb. Naturally, in addition to packing the largest amount of glitter possible in your device, you have also created a computer terminal that allows me to choose which wire to cut from four possible wires: red, green, yellow, and blue. Once the program begins, the user only has X seconds to make a choice or the glitter shower begins regardless of what wire is cut.

The glitter bomb explodes immediately if the yellow or red wires are cut. It is disarmed if the blue wire is cut. If the green wire is cut, the timer is reset, and the user is given the choice of the red, yellow, and blue wires again with the same outcomes as before (blue = disarmed; yellow or red = glitter).

Problem

Create the computer interface for your glitter bomb. It should follow the outline below.

1) Prompt the user to input a character that corresponds to the first letter of the wire to cut. Show them their options somehow in a nicely formatted menu or other easily understood interface.

2) Checks the input for a valid entry. If not a valid entry, ask again until the input is correct. If they fail after 4 tries additional tries (total of 5 attempts), display ‘GLITTER’ to the command window and end the program.

3) Once their input is correct, display a message to the command window that says ‘GLITTER’ (red or yellow wire cut or timer exceeds X seconds), ‘DISARMED’ (blue wire cut, timer at X seconds or less), or that the timer has reset and they must select again (green wire).

4) If the user cuts the green wire, ask for a new input but do NOT check its validity. The bomb is disarmed ONLY if they cut the blue wire within X seconds or less. If they cut the yellow or red wire, wait X seconds or more, or type anything besides the blue wire option, then display ‘GLITTER.

Your program should wait until the user makes a valid input, and then check to see whether the time it took to select an input equaled or exceeded the time limit. You do NOT have to abort the input step and detonate the glitter bomb after X seconds.

I started to code it and here is a picture of what I did

%% Declea ration : 12 13 - 14 - 15 - 16 - 17 18 19 20 21- red = r yellow y blue = y ; %% Inputs ColorOfwire -input( Choose a color for you wire : inter b if you choose the blue wire, y if you choose if (ColorOfwirenz red) -1 (ColorOfWireNE yellow) ↓ (Color0fwi re ~= bLue) ↓ (Color0fwirenzg reen) 23 - 24 25 - 26 - 27 28 - 29 - 30 - 31- 32 elseif ColorOfWire red Il color0fwire= yellow fprintf(Boom) elseif Color0fWires blue fprintf( disarm) elseif ColorOfwire == green end 34

%% Declea ration : 12 13 – 14 – 15 – 16 – 17 18 19 20 21- red = ‘r yellow ‘y’ blue = ‘y’ ; %% Inputs ColorOfwire -input( ‘Choose a color for you wire : inter b if you choose the blue wire, y if you choose if (ColorOfwirenz red) -1 (ColorOfWireNE yellow) ↓ (Color0fwi re ~= bLue) ↓ (Color0fwirenzg reen) 23 – 24 25 – 26 – 27 28 – 29 – 30 – 31- 32 elseif ColorOfWire red Il color0fwire= yellow fprintf(‘Boom’) elseif Color0fWires blue fprintf( ‘disarm) elseif ColorOfwire == green end 34

Expert Answer

 

% Matlab program for glitter bomb problem

clc;
% Declaration

timer_allowed = 5; %timer is set to 5 seconds. X=5

attempts =1;

tic; % starting the timer
%Inputs
colorOfWire = input(‘Choose the color of the wire(enter b for Blue, g for Green ,r for Red, y for Yellow ): ‘,’s’);
% loop continues until valid option is entered
while attempts < 5
if strcmp(colorOfWire,’b’) || strcmp(colorOfWire,’g’) || strcmp(colorOfWire,’r’) || strcmp(colorOfWire,’y’)
break;
end

attempts = attempts + 1
colorOfWire = input(‘Choose the color of the wire(enter b for Blue, g for Green ,r for Red, y for Yellow ): ‘,’s’);

end
tElapsed=toc; % stopping the timer after input

if strcmp(colorOfWire, ‘r’) || strcmp(colorOfWire,’y’) || tElapsed > timer_allowed %user enter red or yellow or timer exceeds 5 seconds
disp(‘GLITTER’);
elseif strcmp(colorOfWire,’b’) && tElapsed <=timer_allowed %user enters blue and timer is less than 5 seconds
disp(‘DISARMED’);
elseif strcmp(colorOfWire,’g’) % user enters green
tic; % timer reset
colorOfWire = input(‘Timer has reset. n Please select the color of the wire again(enter b for Blue, r for Red, y for Yellow ): ‘,’s’);
tElapsed = toc; % timer stop

if strcmp(colorOfWire,’b’) && tElapsed<=timer_allowed % user enters blue
disp(‘DISARMED’);
elseif tElapsed >timer_allowed % timer exceeds 5 seconds
disp(‘GLITTER’);
else % user enters anything else than blue
disp(‘GLITTER’);
end

else

disp(‘GLITTER’);
end

Output:

Question & Answer: I am trying to code a program for a glitter bomb by MATLAB and by using if and while conditions :..... 1

Still stressed from student homework?
Get quality assistance from academic writers!