E. Final Program with Comments

High Low



close all

fprintf(‘Welcome to High Low! One die will be rolled and youll have to guess what number itll land on.’);

x = input(‘\nWhat number do you think the die will land on?\n’); %% Asks for your guess

y = 1;

die = randi(6,1,1);                                        %% Randomly generates a number 1-6

if x <= 0

fprintf(‘Really bruh…\n’)                                %% Phrases if you guess a number not on a die

elseif x >= 7

fprintf(‘Are you kidding me…\n’)


while x ~= die                                             %% While loop keeps track of attempts and gives feedback if you’re too high or low

if x > die

    y = y +1;

    fprintf(‘\nYour guess was too high, guess again\n’);

    x = input(‘\nWhat number do you the die will land on?\n’);


elseif x < die

    y = y +1;

    fprintf(‘\nYour guess was too low, guess again\n’);

    x = input(‘\nWhat number do you the die will land on?\n’);




fprintf(‘\nCorrect, you win!!\n’);                         %% Prints you won, with a different phrase based off attempts

if y == 1

    fprintf(‘\nYou are literally a god\n’);

elseif y == 6

    fprintf(‘\nIt took you %i guesses, please never play again \n’,y);

elseif y == 2

    fprintf(‘Wow… youre almost good at the game, keep trying bud\n’,y);


    fprintf(‘\nIt took you %i guesses, come on man \n’,y);





close all

fprintf(‘Welcome to Tenzi! Youll roll 10 dice and the goal is to get all of them to be the same number.\nAfter the first roll pick a number to put to the side.’);

play = input(‘Would you like to play Tenzi? Enter “1” for yes and “0” for no\n’); %% Asks if the user wants to play

if play == 1     %% If they do want to play it creates a vector of ten rolled dice

    roll1 = randi(6,1,10)

    side = input(‘What number do you want to put to the side?\n’);

elseif play == 0

    fprintf(‘Oof ok, well game over\n’);



dicerolled = 0;     %% Takes first roll and asks what number you want to keep then puts then goes through vector and counts how many values there are then takes it away

k = 0;

i = 0;

for i = 1:length(roll1)

    if roll1(i) == side

        total = k + 1;

        k = k + 1;

        i = i + 1;

        dicerolled = dicerolled + 1;


        i = i + 1;

        dicerolled = dicerolled + 1;




rolls = randi(6,1,10-total);

while rolls ~= 0        %% While there are dice left it rolls all the die and takes away dice when it matches your number and keep track of how many total dice you had to roll

rolls = randi(6,1,10-total)

n= 0;

for n = 1:(10-total);

if rolls(n) == side;

    total = k + 1;

    k = k + 1;

    n = n + 1;

    dicerolled = dicerolled + 1;


    n = n + 1;

    dicerolled = dicerolled + 1;






fprintf(‘You won Tenzi!\nYou had to roll %i die to win!\n’ , dicerolled);   %% Displays that you won and how many dice you rolled to win

Adventure Game



close all

fprintf(‘Welcome to our adventure game. Please enter yes or no as you try to defend yourself from the robbers.\n’); %Instructions

play = input(‘Do you wanna go on an adventure?\n’ , ‘s’); %Ask if you wanna play

ans = length(play);

c2a = 0; %Intializing all values as zero

c2b = 0;

c3a = 0;

c3b = 0;

c3c = 0;

c3d = 0;

c4a = 0;

c4f = 0;

if ans == 3

    fprintf(‘You seemed to have just woken up in your house but its very quiet…\nYou get up and no one seems to be home.\n’);

choice1 = input(‘Suddenly your phone rings and its from an unknown caller do you pick up? yes or no?\n’ , ‘s’);

c1 = length(choice1);

if c1 == 3

    choice2a = input(‘You answer the phone and it sounds like your mom, but she seems very concerned\nShe tells you to lock yourself in the bathroom. Do you listen or not?\n’ , ‘s’);

    c2a = length(choice2a);


    choice2b = input(‘You decide not to answer the phone, you continue on with your morning routine…\nSuddenly you think you hear something outside of your house do you go to investigate?\n’ , ‘s’);

    c2b = length(choice2b);


if c2a == 3

    choice3a = input(‘You head up to the bathroom and lock the door…\nYou sit there and the quiet is killing you. You decide to call your mom again, but she doesnt pick up.\nDo you leave the bathroom or no?\n’ , ‘s’);

    c3a = length(choice3a);

elseif c2a == 2

    choice3b = input(‘You dont go to the bathroom thats dumb. You continue with your day when all of a sudden you hear a loud pounding on the door.\nThankfully its locked, however do you go and see whos at the door or no?\n’ , ‘s’);

    c3b = length(choice3b);

elseif c2b == 3

    choice3c = input(‘You decide to go to your front door to look out the window, but nothing seems to be off.\nHowever you notice the trash cans have been knocked over and all of a sudden theres a pounding sound coming from the back of the house.\nDo you go to investigate again?\n’ , ‘s’);

    c3c = length(choice3c);


    choice3d = input(‘You choose not to do anything, continuing on with your daily routine.\nOut of no where your mom calls again…\nDo you pick up the phone?\n’ , ‘s’);

    c3d = length(choice3d);


if c3a == 3 %If your answer equals certain lengths it goes through series of loops based on length of answer

    choice4a = input(‘You leave the bathroom and hear a pounding on the back door.\nDo you leave the bathroom to investigate?\n’ , ‘s’ );

    c4a = length(choice4a);

elseif c3a == 2

    choice4b = input(‘You stay in the bathroom and eventually fall asleep…\nYou wake up to your mom thanking you for listening.\nEverything seemed to work out and you survived the robbers.\n>>>\n’ , ‘s’);

    %c4b = length(choice4b);

elseif c3b == 3

    choice4c = input(‘You decide to go see whats going on at the front door..\nSadly the backdoor was unlocked and one of the robbers throws a burlap bag over your head and youve been kidnapped.\nGame over…\n’ , ‘s’);

    %c4c = length(choice4c);

elseif c3b == 2

    choice4d = input(‘You decide to ignore it and watch tv.\nSadly the backdoor was unlocked and one of the robbers throws a burlap bag over your head and youve been kidnapped.\nGame over…\n’ , ‘s’);

    %c4d = length(choice4d);

elseif c3c == 3

    choice4e = input(‘You decide to go check out the back door…\nAll of a sudden see see a man dressed in all black, you race to go lock the door and call the police.\nThey tell you to just sit tight til they arrive\nThe police arrive and arrest the robbers congrats on surviving.\n’ , ‘s’);

    %c4e = length(chocie4e);

elseif c3c == 2

    choice4f = input(‘You choose not to investigate, but you find something to defend yourself with cause you have a bad feeling.\nAll of a sudden you hear the back door creak open…\nDo you approach the door?\n’ , ‘s’);

    c4f = length(choicef);

elseif c3d == 3

    choice4g = input(‘You decide to pick up the phone and she tells you to lock all the doors and windows, and fast!\nAs you go to lock everything you hear noises…\nAll of a sudden a man comes up behinds you and knocks you out unconscious while they rob your house.\nGame over.\n’ , ‘s’);

    %c4g = length(choice4g);


    choice4h = input(‘You ignore the call and before you know it four strange men have rushed into your house and knocked you unconscious and robbed your home blind.\nShouldve listened to your mom…\nGame over.\n’ , ‘s’);

    %c4h = length(choice4h);


if c4a == 3

    choice5a = input(‘You leave to investigate, but this time you bring a bat with you.\nYou end up going to the back door and find 3 men staring in.\nThey see you with the bat and run away.\nCongrats you have defended your house from the robbers!\n’ , ‘s’);

elseif c4a == 2

    choice5b = input(‘You stay in the bathroom and eventually fall asleep.\nYou wake up hours later to find your house robbed clean of everything valuable within it.\nGame over\n’ , ‘s’);

elseif c4f == 3

    choice5c = input(‘You decide to approach the door and attack first.\n You end up cracking two men with your bat one by one and fend off the robbers and call the police to arrest them.\nCongrats you defend your house from the robbers!\n ‘ ,‘s’);


    choice5d = input(‘You decide to stay put and the robbers attack you from both sides knocking you unconscious as you try to call the police.\nYour house got robbed of everything valuable within it…\nGame over\n’ , ‘s’);


else %If they said no end game

    fprintf(‘Ok, goodbye\n’);