Connect 4 Game
%% Connect 4 Game
% This game utilizes a graphic downloaded off the internet to display the
% gameboard of the classic board game, Connect 4
% Rules for Connect 4 game
r=input(‘Would you like to hear the rules of Connect Four? Enter 1 for yes of 0 for no: ‘);
if r==1
fprintf(‘\n 1. The win you must be the first player to get four of your color chips in a row’)
fprintf(‘\n 2. This can be done horizontally, vertically, or diagonally’)
fprintf(‘\n 3. You will alternate picking a column to place a chip into with the other player’)
fprintf(‘\n 4. To enter a chip inset a number 1-7, 1 being the left most column and 7 being the right most column’)
fprintf(‘\n 5. Since you now know the rules, you are ready to play\n’)
else
fprintf(‘\n Great, since you already know the rules you are ready to play!\n’)
end
% The load Connect function loads the game graphics downloaded from the
% internet
load (‘Connect.mat’)
% Sets the outer while loop equal to false. When this variable is changed
% to true, the outer loop will break and the game will end
isTrue = false;
% Set accumulators equal to 0
chipsConnected = 0;
redChipsEntered = 0;
blackChipsEntered = 0;
% Create row vector. Every time a player chooses a column to insert a chip
% into, MATLAB will subtract 1 from the corresponding column of the vector
% so that if another player puts another chip in that same column, the chip
% will fall on top of the other chip and not replace the chip in that
% previous position
x=[8,8,8,8,8,8,8,8,8];
% The imshow command displays the game board and will run after each player
% makes a move to update the positions of where the chips are
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
% This for loop generates an empty matrix of 0’s, defined as “matrix”,
% identical to that of the gameboard to make it easier for MATLAB to check
% the positions of the chips and determine a winner. It also includes a
% border around the matrix, defined as “3’s” so that if the program checks
% out of the matrix of 0’s for successive chips, then the loop will break
A=[3,3,3,3,3,3,3,3,3];
B=[3,0,0,0,0,0,0,0,3];
matrix=[A;B;B;B;B;B;B;A];
% Outer while loop initiating the start of the game
while isTrue == false
% Prompts the user to pick a column to drop a chip into
column1 = input(‘\nPlayer 1, pick a column to enter a chip into: ‘);
% While loop checking to make sure the user input a valid column
% Inserts the redchip visual into the matrix graphic in the position
% that the user input
Board{x(column1)-2,column1}=redchip;
% Changes a “0” to “1” in “matrix” in the position that the user placed
% the chip
matrix(x(column1)-1,column1+1)=1;
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
% Accumulates the amount of chips entered so MATLAB does not start
% checking for winning combinations when it is not possible to have won
% with less than 4 chips placed (makes code more efficient)
redChipsEntered = redChipsEntered + 1;
% Set accumulators equal to 1
k=1;
q=1;
amountCounted = 1;
% If statement checks if player 1 has entered 4 or more chips into the
% board yet
if redChipsEntered >= 4
% Check successive amounts of chips in a row to see is a winning
% combination has been made and accumulates to variable
% “amountCounted”
while amountCounted < 4 && q == 1
% Checks the column to the right of the chip that was just placed
% by the player for successive chips for successive chips in a
% specific row
while matrix(x(column1)-1,(column1+1)+k)==1 && matrix(x(column1)-1,(column1+1)+k)~=3
% Accumulates the number of successive chips
amountCounted = amountCounted + 1;
% Accumulates k to check the next position in that row
% (i.e. one unit to the right)
k=k+1;
% If the counter accumulates to 4, then the loop is
% broken
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
% This while loop checks for successive chips to the left of
% the position where a player last placed a chip in a specific
% row
% Reset k equal to 1
k=1;
if (column1+1)-k~=0
while matrix(x(column1)-1,(column1-k)+1)==1 && matrix(x(column1)-1,((column1)-k)+1)~=3
% Accumulates the number of successive chips in addition to
% the row check to the right of the position
amountCounted = amountCounted +1;
% Accumulates k to check the next position in that row
% (i.e. one unit to the left)
k=k+1;
% If counter accumulated to 4, then the loop is broken
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
% This set of loops begins counting the number of successive
% chips in the column that the last chip was placed by the user
% Reset the accumulators
amountCounted = 1;
k=1;
% Checks successive rows below the position that the last chip
% was placed in a specific column
if x(column1)+k <= 8 && column1+1 <= 9
while matrix((x(column1)-1)+k,column1+1)~=3 && matrix((x(column1)-1)+k,column1+1)==1
% Accumulates the amount counted for successive chips of
% the same color
amountCounted = amountCounted + 1;
% Accumulates k to change the position on the matrix that
% the program will check for a successive chip
k=k+1;
% If 4 successive chips are found, then the loop will break
if amountCounted == 4
break;
end
end
end
if amountCounted == 4
break;
end
% Reset k
k=1;
% Checks for successive chips in a single column in the rows
% above the chip that was last placed by a player
if x(column1)-k ~= 0
while matrix((x(column1)-1)-k,column1+1)==1 && matrix((x(column1)-1)-k,column1+1)~=3
% Accumulates the amount counted for successive chips of
% the same color
amountCounted = amountCounted + 1;
% Accumulates k to change the position on the matrix that
% the program will check for a successive chip
k=k+1;
% If 4 successive chips are found, then the loop will break
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
% This set of loops will check for successive chips of the same
% color for diagonal combinations in the matrix
%begin diagonally positive
% Reset the accumulators
amountCounted = 1;
k=1;
% Checks for successive chips in a diagonal down and to the
% right of the position that the last chip was placed
while matrix((x(column1)-1)+k,(column1+1)+k)==1 && matrix((x(column1)-1)+k,(column1+1)+k)~=3
% Accumulates the amount counted for successive chips of
% the same color
amountCounted = amountCounted + 1;
% Accumulates k to change the position on the matrix that
% the program will check for a successive chip
k=k+1;
% If 4 successive chips are found, then the loop will break
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
% Reset k
k=1;
% Checks for successive chips in a diagonal up and to the left
% of the position that the last chip was placed
if (x(column1)-1)-k~=0 && (column1+1)-k ~= 0
while matrix((x(column1)-1)-k,(column1+1)-k)==1 && matrix((x(column1)-1)-k,(column1+1)-k)~=3
% Accumulates the amount counted for successive chips of
% the same color
amountCounted = amountCounted + 1;
% Accumulates k to change the position on the matrix that
% the program will check for a successive chip
k=k+1;
% If 4 successive chips are found, then the loop will break
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
% Reset the accumulators
amountCounted = 1;
k=1;
% Checks for successive chips up in a diagonal up and to the
% right of the position that the last chip was placed
if (x(column1)-1)-k~=0
while matrix((x(column1)-1)-k,(column1+1)+k)==1 && matrix((x(column1)-1)-k,(column1+1)+k)~=3
% Accumulates the amount counted for successive chips of
% the same color
amountCounted = amountCounted + 1;
% Accumulates k to change the position on the matrix that
% the program will check for a successive chip
k=k+1;
% If 4 successive chips are found, then the loop will break
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
%Reset k
k=1;
% Checks for succesive chips in a diagonal down and to the left
% of the position that the last chip was placed
if (column1+1)-k ~= 0
while matrix((x(column1)-1)+k,(column1+1)-k)==1 && matrix((x(column1)-1)+k,(column1+1)-k)~=3
% Accumulates the amount counted for successive chips of
% the same color
amountCounted = amountCounted + 1;
% Accumulates k to change the position on the matrix that
% the program will check for a successive chip
k=k+1;
% If 4 successive chips are found, then the loop will break
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
% If no combinations of 4 successive chips are found, then the
% variable q is set to 0 and does not meet the condition of the
% outer while loop, causing the loop to break
q = 0;
end
end
% If 4 successive chips are found, then the variable playerWon is
% assigned to the value 1, for player 1
if amountCounted == 4
playerWon = 1;
break;
end
% This equation manipulates the row vector, x, set at the beginning of
% the code. The program will change a value in the vector based on the
% column that the player entered to place a chip. The program will
% subtract 1 from a value in a vector so that the next chip placed in
% that same colulmn will “fall” onto the previous chip that was placed
% in that column, instead of replacing the chip that was placed
x(column1) = x(column1)-1;
% Refreshes the board graphic to display the chip
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
% The program prompts the second player to enter a column to place a
% chip into
column2 = input(‘Player 2, pick a column to enter a chip into: ‘);
% Inserts the black chip visual into the position that the player
% prompted to enter a chip into on the matrix
Board{x(column2)-2,column2}=blackchip;
% Changes the value from “0” to “2” in “matrix” in the position that the
% user prompted to enter a chip into
matrix(x(column2)-1,column2+1)=2;
% Refreshes the board to update the graphic to display the chip that was
% placed
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
% Accumulates the amount of chips entered so MATLAB does not start
% checking for winning combinations when it is not possible to have won
% with less than 4 chips placed (makes code more efficient)
blackChipsEntered = blackChipsEntered + 1;
% Set the accumulators
k=1;
q=1;
amountCounted = 1;
% The following while loops are the same loops described above to check
% for different combinations of successive chips in order to try and
% find a winner
if blackChipsEntered >= 4
while amountCounted < 4 && q == 1
while matrix(x(column2)-1,(column2+1)+k)==2 && matrix(x(column2)-1,(column2+1)+k)~=3
amountCounted = amountCounted + 1;
k=k+1;
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
k=1;
if (column2+1)-k~=0
while matrix(x(column2)-1,(column2-k)+1)==2 && matrix(x(column2)-1,((column2)-k)+1)~=3
amountCounted = amountCounted +1;
k=k+1;
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
amountCounted = 1;
k=1;
if x(column2)+k<=8 && column2+1 <= 9
while matrix((x(column2)-1)+k,column2+1)~=3 && matrix((x(column2)-1)+k,column2+1)==2
amountCounted = amountCounted + 1;
k=k+1;
if amountCounted == 4
break;
end
end
end
if amountCounted == 4
break;
end
k=1;
if x(column2)-k ~= 0
while matrix((x(column2)-1)-k,column2+1)==2 && matrix((x(column2)-1)-k,column2+1)~=3
amountCounted = amountCounted + 1;
k=k+1;
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
amountCounted = 1;
k=1;
while matrix((x(column2)-1)+k,(column2+1)+k)==2 && matrix((x(column2)-1)+k,(column2+1)+k)~=3
amountCounted = amountCounted + 1;
k=k+1;
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
k=1;
if (x(column2)-1)-k~=0 && (column2+1)-k ~= 0
while matrix((x(column2)-1)-k,(column2+1)-k)==2 && matrix((x(column2)-1)-k,(column2+1)-k)~=3
amountCounted = amountCounted + 1;
k=k+1;
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
amountCounted = 1;
k=1;
if (x(column2)-1)-k~=0
while matrix((x(column2)-1)-k,(column2+1)+k)==2 && matrix((x(column2)-1)-k,(column2+1)+k)~=3
amountCounted = amountCounted + 1;
k=k+1;
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
k=1;
if (column2+1)-k ~= 0
while matrix((x(column2)-1)+k,(column2+1)-k)==2 && matrix((x(column2)-1)+k,(column2+1)-k)~=3
amountCounted = amountCounted + 1;
k=k+1;
if amountCounted == 4
break;
end
end
if amountCounted == 4
break;
end
end
q = 0;
end
end
% If the amount counted accumulates to 4, then the playerWon variable
% will be assigned the value 2, for player 2
if amountCounted == 4
playerWon = 2;
break;
end
% If the whole matrix is filled up without a winning combination, then
% the variable playerWon is assigned the value 3, which results in a
% print statement displaying that the two players tied.
if redChipsEntered == 21 && blackChipsEntered == 21
playerWon = 3;
break;
end
% This equation manipulates the row vector, x, set at the beginning of
% the code. The program will change a value in the vector based on the
% column that the player entered to place a chip. The program will
% subtract 1 from a value in a vector so that the next chip placed in
% that same colulmn will “fall” onto the previous chip that was placed
% in that column, instead of replacing the chip that was placed
x(column2)=x(column2) – 1;
% Refreshes the board graphic to display the chip
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
end
% If the playerWon team is assigned the value 3, then the program will
% display that the players tied
if playerWon == 3
fprintf(‘It is a tie!’)
else
% If the value 3 has not been assigned to playerWon, then The program
% will display that Player 1 or 2 has won the game after the outer
% while loop breaks when amountCounted = 4
fprintf(‘Congrats Player %0.0f, you win!\n’, playerWon)
end
Over Under Seven Game
%The rules for the game. User enters if they want to hear the rules
r=input(‘Would you like to hear the rules of over/under seven? enter a “1” for yes and “0” for no: ‘);
if r==1
fprintf(‘\n 1. The game is played with two dice’)
fprintf(‘\n 2. You specify how much money you want to bet on each roll’)
fprintf(‘\n 3. You have $100 to start with’)
fprintf(‘\n 4. You will then enter “over”, “under”, or “seven” as your prediction for the sum of the two die’)
fprintf(‘\n 5. The dice are then rolled’)
fprintf(‘\n 6. If you bet incorrectly you lose the amount of money you bet’)
fprintf(‘\n 7. If you bet correctly for over or under, then you win your bet’)
fprintf(‘\n 8. If you bet correctly for exactly seven, you win four times the amount of your bet’)
fprintf(‘\n 9. You can start with any bet less than or equal to 100 dollars and continue until you run out of money or quit the game’)
fprintf(‘\n 10. There can be no negative bets’)
fprintf(‘\n 11. Since you know the rules now, you are ready to play!’)
else
fprintf(‘\n Great, since you already know the rules you are ready to play’)
end
%initializing amount of money and loading the dice
currentPool = 100;
load Dice;
fprintf(‘\n You have %0.0f dollars.’, currentPool)
bet = input(‘\nEnter an amount to bet (0 to quit): ‘);
%while loop loops until player loses or quits
while bet ~= 0 && currentPool ~= 0
%does not let user bet outside of range
while bet < 0 || bet > currentPool
fprintf(‘\nYour bet must be between 0 and %0.0f.’, currentPool)
bet = input(‘\nEnter an amount to be (0 to quit): ‘);
end
%takes in string input from user of their bet
highLowS = input(‘\nHigh, low, or sevens? ‘, ‘s’);
%converts to lower case in case user enters not all lower case
highLow = lower(highLowS);
%comparing the string to see if the user entered high, low, or seven
compare1 = strcmp(highLow,’high’);
compare2 = strcmp(highLow,’low’);
compare3 = strcmp(highLow,’sevens’);
%if user does not enter one of these words, the loop runs until they do
while compare1 == 0 && compare2 == 0 && compare3 == 0
fprintf(‘\nEnter a valid input.’)
highLowS = input(‘\nHigh, low, or sevens? ‘, ‘s’);
highLow = lower(highLowS);
compare1 = strcmp(highLow,’high’);
compare2 = strcmp(highLow,’low’);
compare3 = strcmp(highLow,’sevens’);
end
%getting the random integers
roll1 = randi(6);
roll2 = randi(6);
%creating array to display in dice
rollA = [roll1,roll2];
imshow( [ Dice{rollA} ] );
%printing out the rolls
fprintf(‘\nDie 1 rolls: %0.0f’, roll1)
fprintf(‘\nDie 2 rolls: %0.0f’, roll2)
%calculating the value of the two rolls
roll = roll1 + roll2;
%displaying value
fprintf(‘\nThe total of the two rolls is %0.0f.’, roll)
%initializing winnings variable to calculate amount won or lost
winnings = 0;
%if-else statements to see if the user entered high, low, or sevens
%if the user entered high
if compare1 == 1
%if-else statement to see if the user won or lost
%if it was higher, they won
if roll > 7
%winnings is a positive value
winnings = winnings + bet;
%winnings displayed
fprintf(‘\nYou won %0.0f dollars.’, bet)
%otherwise they lost
else
%winnings is a negative value
winnings = winnings – bet;
%winnings are displayed
fprintf(‘\nYou lost %0.0f dollars.’, bet)
end
%if the user entered low
elseif compare2 == 1
%if it is lower they won
if roll < 7
winnings = winnings + bet;
fprintf(‘\nYou won %0.0f dollars.’, bet)
%otherwise they lost
else
winnings = winnings – bet;
fprintf(‘\nYou lost %0.0f dollars.’, bet)
end
%if the user entered sevens
elseif compare3 == 1
%if it is seven they won
if roll == 7
winnings = winnings + (4*bet);
fprintf(‘\nYou won %0.0f dollars.’, bet)
%otherwise they lost
else
winnings = winnings – bet;
fprintf(‘\nYou lost %0.0f dollars.’, bet)
end
end
%adding the winnings to the current pool
currentPool = currentPool + winnings;
%displaying the amount of money the user has
fprintf(‘\nYou have %0.0f dollars.’, currentPool)
%asking the user to enter another bet if the current pool is not 0
if currentPool ~= 0
bet = input(‘\nEnter an amount to bet (0 to quit): ‘);
end
end
%if the user quits, the amount of money left is displayed to the user again
if bet == 0
fprintf(‘\nYou have %0.0f dollars.’, currentPool)
end
%message displayed at the end
fprintf(‘\nThanks for playing!’)
Rock Paper Scissors Game
%% Rock Paper Scissors Game
% Play the classic game of rock paper scissors against the computer!
% Includes a cumulative scoreboard
% Rules for rock paper scissors
r=input (‘Would you to hear the rules for rock paper scissors? enter “1” for yes and “0” for no: ‘);
if r==1
fprintf(‘\n 1. The computer will pick either rock, paper, or scissors’)
fprintf(‘\n 2. You will need to pick rock, paper or scissors that will rival the computer by entering 1, 2, or 3’)
fprintf(‘\n 3. Rock beats scissors, paper beats rock, and scissors beats paper’)
fprintf(‘\n 4. Now that you know the rules you are ready to play’)
else
fprintf(‘Great, since you already know the rules you are ready to play!’)
end
% Prompt the user to enter a value corresponding to either rock, paper, or
% scissors
choice = input(‘\n Enter 1 for rock, 2 for paper, or 3 for scissors, or enter 0 to quit: ‘);
% A value error loop to ensure that the user does not enter a value other
% than 1, 2, 3, or 0
while choice ~= 1 && choice ~= 2 && choice ~= 3 && choice ~= 0
fprintf(‘\nPlease enter 1, 2, or 3 to play or 0 to quit.’)
choice = input(‘\nEnter 1 for rock, 2 for paper, or 3 for scissors, or enter 0 to quit: ‘);
end
% Sets the score accumulators to 0
computerScore = 0;
userScore = 0;
% Loop to generate either rock, paper, or scissors for the computer
while choice ~= 0
rand = randi(3);
if rand == 1
computerChoice = ‘rock’;
elseif rand == 2
computerChoice = ‘paper’;
else
computerChoice = ‘scissors’;
end
% Displays which option the computer chose
fprintf(‘Computer chose %s\n’, computerChoice)
% Compares computer choice with user choice when the user chose rock
if choice == 1
if rand == 1
fprintf(‘It is a tie!’)
elseif rand == 2
fprintf(‘Computer wins!’)
% Accumulates score for the computer
computerScore = computerScore + 1;
else
fprintf(‘You win!’)
% Accumulates score for user
userScore = userScore + 1;
end
% Compares computer choice with user choice when the user chose paper
elseif choice == 2
if rand == 1
fprintf(‘You win!’)
userScore = userScore + 1;
elseif rand == 2
fprintf(‘It is a tie!’)
else
fprintf(‘Computer wins!’)
computerScore = computerScore + 1;
end
% Compares computer choice with user choice when the ucer chose scissors
else
if rand == 1
fprintf(‘Computer wins!’)
computerScore = computerScore + 1;
elseif rand == 2
fprintf(‘You win!’)
userScore = userScore + 1;
else
fprintf(‘It is a tie!’)
end
end
% Prompts user to redefine the variable choice so the user can keep playing
% the game or quit
choice = input(‘\nEnter 1 for rock, 2 for paper, or 3 for scissors, or enter 0 to quit: ‘);
while choice ~= 1 && choice ~= 2 && choice ~= 3 && choice ~= 0
fprintf(‘\nPlease enter 1, 2, or 3 to play or 0 to quit: ‘)
choice = input(‘\nEnter 1 for rock, 2 for paper, or 3 for scissors, or enter 0 to quit: ‘);
end
end
% Displays the score after the user decides to exit the game and stop
% playing
fprintf(‘\nThanks for playing!’)
fprintf(‘\nYour score: %0.0f’, userScore)
fprintf(‘\nComputer score: %0.0f\n’, computerScore)
What are the Odds? Game
%% What are the Odds? Game
% To play this game, the computer will ask the user what the odds are that
% the user will complete a dare randomly generated by the computer. The
% user will then enter a number between 1 and the odds that the user
% prompted the computer to use. Then, the computer will randomly generate a
% number between those same bounds, and if the user input number and
% computer number matches, then you must complete the dare!
%Rules
r=input(‘Would you like to hear the rules of over under seven? Enter 1 for yes, 0 for no: ‘);
if r==1
fprintf(‘\n 1. The computer will ask you for the odds you want them to be between’)
fprintf(‘\n 2. You will enter the number to define the odds bounds’)
fprintf(‘\n 3. You will then enter a number between the bounds for the random dare’)
fprintf(‘\n 4. The computer will then randomly generate a number within the bounds’)
fprintf(‘\n 5. If the number you entered and the one the computer generated match you have to complete the dare’)
fprintf(‘\n 6. If they number you entered and the one the computer generated do not match, you don not have to do the dare’)
fprintf(‘\n 7. You may continue playing until you enter “0” to quit’)
fprintf(‘\n 8. Since you understand the rules you are ready to play!\n’)
else
fprintf(‘\n Since you already know how to play what are the odds, lets play!’)
end
% Initialize the choice variable
choice = 1;
while choice ~= 0
% Randomly generate a dare
rand1 = randi(21);
fprintf(‘\n What are the odds that you ‘)
if rand1 == 1
fprintf(‘eat a pile of salt?’)
elseif rand1 == 2
fprintf(‘do your best Batman impression?’)
elseif rand1 == 3
fprintf(‘prank call Grandma?’)
elseif rand1 == 4
fprintf(‘dump a cup of ice water over your head?’)
elseif rand1 == 5
fprintf(‘stuff as many marshmallows into your mouth as you can?’)
elseif rand1 == 6
fprint(‘switch clothes with someone?’)
elseif rand1 == 7
fprintf(‘talk in the third person?’)
elseif rand1 == 8
fprintf(‘send someone a text that says, “I know what you did last summer”?’)
elseif rand1 == 9
fprintf(‘get wrapped from head to toe in toilet paper?’)
elseif rand1 == 10
fprintf(‘tell someone you have a Yahoo account?’)
elseif rand1 == 11
fprintf(‘put all your clothes on backwards?’)
elseif rand1 == 12
fprintf(‘make a face mask out of sliced cheese?’)
elseif rand1 == 13
fprintf(‘wear a toilet paper turbine for the rest of the day?’)
elseif rand1 == 14
fprintf(‘take a bite out of a stick of butter?’)
elseif rand1 == 15
fprintf(‘have a full conversation with a broom?’)
elseif rand1 == 16
fprintf(‘go outside and shout “Happy New Year.”?’)
elseif rand1 == 17
fprintf(‘spin around 10 times and try to walk in the straight line?’)
elseif rand1 == 18
fprintf(‘bite into a lemon slice?’)
elseif rand1 == 19
fprintf(‘stick jelly between your toes and leave it there for 20 minutes?’)
elseif rand1 == 20
fprintf(‘draw a face on your stomach and make it tell everyone in the room to have a nice day?’)
elseif rand1 == 21
fprintf(‘do a model runway walk on the sidewalk?’)
elseif rand1 == 22
fprintf(‘Tapingo 50 hash browns from McDonalds?’)
end
% Prompt the user to input the odds to do the dare
odds = input(‘\nEnter the top bound of the odds: ‘);
% Have the user enter a number within the bounds of the odds to compare to
% the computer
user_odds = input(‘\nEnter your odds!: ‘);
% Have the computer generate a random number in the bounds to compare to
% the users odds
rand2 = randi(odds);
fprintf(‘The computer chose %i!\n’, rand2)
% Compare the odds of the user and computer
if rand1 == 1 && user_odds == rand2
fprintf(‘You have to eat a pile of salt!’)
elseif rand1 == 1 && user_odds ~= rand2
fprintf(‘You do not have to eat a pile of salt.’)
elseif rand1 == 2 && user_odds == rand2
fprintf(‘You have to do your best Batman impression!’)
elseif rand1 == 2 && user_odds ~= rand2
fprintf(‘You do not have to do your best Batman impression.’)
elseif rand1 == 3 && user_odds == rand2
fprint(‘You have to prank call Grandma!’)
elseif rand1 == 3 && user_odds ~= rand2
fprintf(‘You do not have to prank call Grandma.’)
elseif rand1 == 4 && user_odds ~= rand2
fprinft(‘You have to dump a cup of ice water over your head!’)
elseif rand1 == 4 && user_odds ~= rand2
fprintf(‘You do not have to dump a cup of ice water over your head.’)
elseif rand1 == 5 && user_odds == rand2
fprintf(‘You have to stuff as many marshmallows into your mouth as you can!’)
elseif rand1 == 5 && user_odds ~= rand2
fprintf(‘You do not have to stuff as many marshmallows into your mouth as you can.’)
elseif rand1 == 6 && user_odds == rand2
fprintf(‘You have to switch clothes with someone!’)
elseif rand1 == 6 && user_odds ~= rand2
fprintf(‘You do not have to switch clothes with someone.’)
elseif rand1 == 7 && user_odds == rand2
fprintf(‘You have to talk in the third person!’)
elseif rand1 == 7 && user_odds ~= rand2
fprintf(‘You do not have to talk in the third person.’)
elseif rand1 == 8 && user_odds == rand2
fprintf(‘You have to send someone a text that says, “I know what you did last summer”!’)
elseif rand1 == 8 && user_odds ~= rand2
fprintf(‘You do not have to send someone a text that says, “I know what you did last summer”.’)
elseif rand1 == 9 && user_odds == rand2
fprintf(‘You have to get wrapped from head to toe in toilet paper!’)
elseif rand1 == 9 && user_odds ~= rand2
fprintf(‘You do not have to get wrapped from head to toe in toilet paper.’)
elseif rand1 == 10 && user_odds == rand2
fprintf(‘You have to tell someone you have a Yahoo account!’)
elseif rand1 == 10 && user_odds ~= rand2
fprintf(‘You do not have to tell someone you have a Yahoo account.’)
elseif rand1 == 11 && user_odds == rand2
fprintf(‘You have to put all your clothes on backwards!’)
elseif rand1 == 11 && user_odds ~= rand2
fprintf(‘You do not have to put all your clothes on backwards.’)
elseif rand1 == 12 && user_odds == rand2
fprintf(‘You have to make a face mask out of sliced cheese!’)
elseif rand1 == 12 && user_odds ~= rand2
fprintf(‘You do not have to make a face mask out of sliced cheese.’)
elseif rand1 == 13 && user_odds == rand2
fprint(‘You have to wear a toilet paper turbine for the rest of the day!’)
elseif rand1 == 13 && user_odds ~= rand2
fprintf(‘You do not have to wear a toilet paper turbine for the rest of the day.’)
elseif rand1 == 14 && user_odds == rand2
fprinft(‘You have to take a bite out of a stick of butter!’)
elseif rand1 == 14 && user_odds ~= rand2
fprintf(‘You do not have to take a bite out of a stick of butter.’)
elseif rand1 == 15 && user_odds == rand2
fprintf(‘You have to have a full conversation with a broom!’)
elseif rand1 == 15 && user_odds ~= rand2
fprintf(‘You do not have to have a full conversation with a broom.’)
elseif rand1 == 16 && user_odds == rand2
fprintf(‘You have to go outside and shout “Happy New Year.”!’)
elseif rand1 == 16 && user_odds ~= rand2
fprintf(‘You do not have to go outside and shout “Happy New Year.”.’)
elseif rand1 == 17 && user_odds == rand2
fprintf(‘You have to spin around 10 times and try to walk in the straight line!’)
elseif rand1 == 17 && user_odds ~= rand2
fprintf(‘You do not have to spin around 10 times and try to walk in the straight line.’)
elseif rand1 == 18 && user_odds == rand2
fprintf(‘You have to bite into a lemon slice!’)
elseif rand1 == 18 && user_odds ~= rand2
fprintf(‘You do not have to bite into a lemon slice.’)
elseif rand1 == 19 && user_odds == rand2
fprintf(‘You have to stick jelly between your toes and leave it there for 20 minutes!’)
elseif rand1 == 19 && user_odds ~= rand2
fprintf(‘You do not have to stick jelly between your toes and leave it there for 20 minutes.’)
elseif rand1 == 20 && user_odds == rand2
fprintf(‘You have to draw a face on your stomach and make it tell everyone in the room to have a nice day!’)
elseif rand1 == 20 && user_odds ~= rand2
fprintf(‘You do not have to draw a face on your stomach and make it tell everyone in the room to have a nice day.’)
elseif rand1 == 21 && user_odds == rand2
fprintf(‘You have to do a model runway walk on the sidewalk’)
elseif rand1 == 21 && user_odds ~= rand2
fprintf(‘You do not have to do a model runway walk on the sidewalk.’)
elseif rand1 == 22 && user_odds == rand2
fprintf(‘You have to Tapingo 50 hash browns from McDonalds!’)
elseif rand1 == 22 && user_odds ~= rand2
fprintf(‘You do not have to Tapingo 50 hash browns from McDonalds.’)
end
% Ask the user if they want to continue
choice = input(‘\nWould you like to continue? Enter “1” for yes and “0” to quit: ‘);
fprintf(‘\n’)
end