Geeks With Blogs

Melanie Draves programming and what not

Since I love case-statements, I decided to make the most out of them during the rock, paper, scissors program.

The gist of the pseudo-code I wrote up for the program is below.

/*
CIS 217 Midterm
Melanie Draves
04 Mar 2012
Pseudo-code

Narrative dsecription
Program will simulate a game of Rock-Paper-Scissors.  To do this, the program will
generate a number at random from 1-3, which is to be the computer's selection.
Once user selects their choice, the answer and winner will be revealed.
Then the user can choose to start another game or exit the program.
Selection
1 rock
2 paper
3 scissors

Variables
Inputs
userchoice  int
Outputs
compchoice int (the random num)
Temps
outcome  int

Pseudo-code
1    compchoice = generate random number
2    userchoice = call GetUserChoice();
3    outcome = call DetOutcome(compchoice, userchoice)
4    call DispWinner(outcome)
HALT

-----
method DetOutcome(int lcompchoice, luserchoice)
returns: int

loutcome int

switch(lcompchoice)
case 0:
if (luserchoice < 1)
then TIE     //loutcome = 1
elseif (luserchoice > 1)
then lcompchoice = WINNER //loutcome = 2
else lcompchoice = LOSER       //loutcome = 3

case 1:
if (luserchoice = 1)
then TIE    //loutcome = 4
elseif (luserchoice > 1)
then lcompchoice = LOSER    //loutcome = 5
else lcompchoice = WINNER //loutcome = 6

case 2:
if (luserchoice > 1)
then TIE    //loutcome = 7
elseif (luserchoice < 1)
then lcompchoice = LOSER       //loutcome = 8
else lcompchoice = WINNER    //loutcome = 9
default:

return(loutcome)

-----
method DispWinner(int loutcome)
return: void

msg1 string "TIE!, select Go to play again"
msg2 string "YOU WIN!, select Go to play again"
msg3 string "I WIN!, select Go to play again"

show compchoiceLabel
show userchoiceLabel
switch(loutcome)
case 1:
display "Your Choice = Rock ; My Choice = Rock"
display msg1
case 2:
display "Your Choice = Scissors; My Choice = Rock"
display msg3
case 3:
display "Your Choice = Paper ; My Choice = Rock"
display msg2
case 4:
display "Your Choice = Paper ; My Choice = Paper"
display msg1
case 5:
display "Your Choice = Scissors ; My Choice = Paper"
display msg2
case 6:
display "Your Choice = Rock ; My Choice = Paper"
display msg3
case 7:
display "Your Choice = Scissors ; My Choice = Scissors"
display msg1
case 8:
display "Your Choice = Rock ; My Choice = Scissors"
display msg2
case 9:
display "Your Choice = Paper ; My Choice = Scissors"
display msg3
default:
return
*/

Posted on Sunday, March 4, 2012 6:41 PM Beginning C# | Back to top

Comments on this post: Rock, Paper Scissors program - pseudo-code

No comments posted yet.
Your comment:
(will show your gravatar)

Popular Posts on Geeks with Blogs 0
Geeks With Blogs Content Categories ASP.Net SQL Server Apple Google SharePoint Windows Visual Studio Team Foundation Server Agile Office Design Patterns Web Azure
Brand New Posts on Geeks with Blogs 0