Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to make a loop that loops a specific number of times ?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sdn121019




PostPosted: Sat Apr 18, 2020 3:48 pm   Post subject: How to make a loop that loops a specific number of times ?

Hello, this is my first post.
I have a school project where I have to make a rock paper scissors assignment that lets the player play the game a specific number of times by entering how many points they want to play to against a computer.
Currently the program runs perfectly fine but when the player plays the game the game just keeps looping forever.
Pls help..

Here is the code I currently have:

var randNum : int
var myNum : int
var playagain : char
var playername : string
var score : int

randNum := Rand.Int (1, 3)

const ROCK : int := 1
const PAPER : int := 2
const SCISSORS : int := 3

put "Hello Player! What's your name?"
get playername
put "Welcome ", playername, "! How many points do you want to play to?"
get score


delay (100)
put "Loading game..."
delay (3500)
cls

loop

put "Choose:"
put ""
put " 1. ROCK"
put " 2. PAPER"
put " 3. SCISSORS"

get myNum


if myNum = 1 then
put "YOU CHOSE ROCK"
elsif myNum = 2 then
put "YOU CHOSE PAPER"
elsif myNum = 3 then
put "YOU CHOSE SCISSORS"
end if

if randNum = 1 then
put "COMPUTER CHOSE ROCK"
elsif randNum = 2 then
put "COMPUTER CHOSE PAPER"
elsif randNum = 3 then
put "COMPUTER CHOSE SCISSORS"
end if


if myNum = 1 and randNum = 1 then
put "YOU TIED!"
end if
if myNum = 1 and randNum = 2 then
put "YOU LOSE!"
end if
if myNum = 1 and randNum = 3 then
put "YOU WIN!"
end if

if myNum = 2 and randNum = 1 then
put "YOU WIN!"
end if
if myNum = 2 and randNum = 2 then
put "YOU TIED!"
end if
if myNum = 2 and randNum = 3 then
put "YOU LOSE!"
end if

if myNum = 3 and randNum = 1 then
put "YOU LOSE!"
end if
if myNum = 3 and randNum = 2 then
put "YOU WIN!"
end if
if myNum = 3 and randNum = 3 then
put "YOU TIED!"
end if

end loop
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: