none
Small Basic slot machine program RRS feed

  • Question

  • I am trying to write a small basic slot machine program for a class I am taking and I am having trouble figuring out how to get it to tell the user how much they have bet and how much they have won. Basically the user bets any amount between 1 and 100 and then the computer returns 3 items out of 6 items. If all three match (cherries cherries cherries or bars bars bars...) then the user wins 3x their bet. For two of the same they win 2x their bet and for no match they win nothing. Then they can choose to play again or not. When they are completely done playing the computer should tell the user the total amount the user bet as well as the total amount the user won (not less their bets). 

    I am pasting my program below \/\/\/\/

    TextWindow.WriteLine("This program asks a bet in an amount between $1 and $100. Any amount that ")
    TextWindow.WriteLine("you bet between a whole dollar amount will be rounded to the closest dollar")
    TextWindow.WriteLine("Three words will be selected out of a total of six words.")
    TextWindow.WriteLine("When all three words match you win 3X your bet")
    TextWindow.WriteLine("When two words match you win 2X your bet")
    TextWindow.WriteLine("When none of the words match you lose")
    TextWindow.WriteLine(" ")

    '-------------------------------------------------------------------------------------------------------------------------------------


    gamblingAmount()
    gambling = Math.Round(gambling)


    While (gambling < 1 Or gambling > 100)
        TextWindow.WriteLine("The amount you entered is invalid. A valid amount must be between ")
        TextWindow.WriteLine("$1 and $100. Please try again.")
        TextWindow.WriteLine(" ")
        gamblingAmount ()
        
          EndWhile
          
          '-------------------------------------------------------------------------------------------------------------------------------------
          
    playAgain = "y"

    While (playAgain = "y")
      ' play a round
     
    gamblingAmount() 
     makeBet()
      
     TextWindow.Write("Do you want to play again? (y/n) >> ")
     playAgain = TextWindow.Read()
     
        TextWindow.WriteLine("")
      
      
    EndWhile
    '-------------------------------------------------------------------------------------------------------------------------------------

    'Tell user how much was won based on

        'a three matches is a 3X win
        'b two matches is a 2X win
        'c no matches is a loss
        
        
    If computerNumber = computerNumberTwo And computerNumberTwo = computerNumberThree Then
      TextWindow.WriteLine("Congratulations, you have won " + gambling * 3 )
    ElseIf computerNumber = computerNumberTwo or computerNumber = computerNumberThree then
      TextWindow.WriteLine("Congratulations, you have won " + gambling * 2)
      elseIf computerNumberThree = computerNumberTwo then
        TextWindow.WriteLine("Congratulations, you have won " + gambling * 2 )
      Elseif computerNumber <> computerNumberTwo and computerNumberTwo <> computerNumberThree then
    TextWindow.WriteLine("Sorry you did not win " )
    EndIf
      
      winningsTotal = gambling 
      TextWindow.WriteLine("Your total bets are " + gambling )
        
    '-------------------------------------------------------------------------------------------------------------------------------------

    'enter the amount to be bet sub
      
      Sub gamblingAmount
        TextWindow.WriteLine("Please enter a whole dollar amount that you would like to gamble ")
        TextWindow.WriteLine("between 1 and 100. ")
        TextWindow.WriteLine(" ")
        gambling = TextWindow.Read()
        TextWindow.WriteLine(" ")
    EndSub


    '-------------------------------------------------------------------------------------------------------------------------------------
    'Random charcacters chosen
      
      Sub makeBet
      
      'choose 3 random numbers from 1 to 6
      computerNumber = Math.GetRandomNumber(6)
      computerNumberTwo = Math.GetRandomNumber(6)
      computerNumberThree = Math.GetRandomNumber(6)
      
        
      'assign Cherries for 1, Oranges for 2, Plums for 3, Bells for 4, Melons for 5, Bars for 6
      
      If (computerNumber = 1) Then
        computerNumber = "Cherries"
      ElseIf (computerNumber = 2) then  
        computerNumber = "Oranges"
         ElseIf (computerNumber = 3) then  
           computerNumber = "Plums"
            ElseIf (computerNumber = 4) then  
        computerNumber = "Bells"
         ElseIf (computerNumber = 5) then  
           computerNumber = "Mellons"
            ElseIf (computerNumber = 6) then  
              computerNumber = "Bars"
       EndIf
       
    If (computerNumberTwo = 1) Then
        computerNumberTwo = "Cherries"
      ElseIf (computerNumberTwo = 2) then  
        computerNumberTwo = "Oranges"
         ElseIf (computerNumberTwo = 3) then  
           computerNumberTwo = "Plums"
            ElseIf (computerNumberTwo = 4) then  
        computerNumberTwo = "Bells"
         ElseIf (computerNumberTwo = 5) then  
           computerNumberTwo = "Mellons"
            ElseIf (computerNumberTwo = 6) then  
              computerNumberTwo = "Bars"
            EndIf
            
    If (computerNumberThree = 1) Then
        computerNumberThree = "Cherries"
      ElseIf (computerNumberThree = 2) then  
        computerNumberThree = "Oranges"
         ElseIf (computerNumberThree = 3) then  
           computerNumberThree = "Plums"
            ElseIf (computerNumberThree = 4) then  
        computerNumberThree = "Bells"
         ElseIf (computerNumberThree = 5) then  
           computerNumberThree = "Mellons"
            ElseIf (computerNumberThree = 6) then  
              computerNumberThree = "Bars"
       EndIf
      
     '------------------------------------------------------------------------------------------------------------------------------------
      'Display computers choice
      
      TextWindow.WriteLine("Here is the first character.... " + computerNumber ) 
      TextWindow.WriteLine("Here is the second character.... " + computerNumberTwo ) 
      TextWindow.WriteLine("Here is the third character.... " + computerNumberThree ) 
      
     '------------------------------------------------------------------------------------------------------------------------------------
     
        
    EndSub


    • Moved by Just Karl Monday, June 22, 2015 2:44 PM Looking for the proper forum.
    • Moved by Just Karl Monday, June 22, 2015 2:48 PM Looking for the proper forum.
    Friday, June 19, 2015 7:57 PM

Answers

All replies

  • Hello,

    The TechNet Wiki Discussion Forum is a place for the TechNet Wiki Community to engage, question, organize, debate, help, influence and foster the TechNet Wiki content, platform and Community.

    Please note that this forum exists to discuss TechNet Wiki as a technology/application.

    As it's off-topic here, I am moving the question to the Where is the forum for... forum.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join('6D73646E5F6B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Monday, June 22, 2015 2:44 PM
  • Hello,

    I am actually moving this to the Small Basic forum.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join('6D73646E5F6B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Monday, June 22, 2015 2:48 PM
  • Karl,

    You should test for winning in the bet-loop and accumulate the winnings. The testing should NOT be delayed till after the end of betting.


    Jan [ WhTurner ] The Netherlands

    Monday, June 22, 2015 3:28 PM
    Answerer