Created
February 20, 2024 06:39
-
-
Save ehlzi/185ea40e9ca5fe2b4345b6572f0ac2d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Module main( ) | |
| // Declare variables | |
| Declare Real amountEntered | |
| Declare Real totalEntered = 0 | |
| Declare Real amountWon | |
| Declare Real totalWon = 0 | |
| Declare String playAgain | |
| Do | |
| // Get user to enter amount of money. | |
| Display “How much money would you like to enter?” | |
| Input amountEntered | |
| Set totalEntered = totalEntered + amountEntered | |
| // Generate and display symbols | |
| Declare Integer symbol1 = random(1, 6) | |
| Declare Integer symbol2 = random(1, 6) | |
| Declare Integer symbol3 = random(1, 6) | |
| DisplaySymbol(symbol1) | |
| DisplaySymbol(symbol2) | |
| DisplaySymbol(symbol3) | |
| // Check for matches and calculate winnings | |
| If symbol1 == symbol2 AND symbol2 == symbol3 Then | |
| Set amountWon = amountEntered * 3 | |
| Display “All three match! Your winnings triple.” | |
| ElseIf symbol1 == symbol2 OR symbol1 == symbol3 OR symbol2 == symbol3 Then | |
| Set amountWon = amountEntered * 2 | |
| Display “You have a match! Your winnings double.” | |
| Else | |
| Set amountWon = 0 | |
| Display “No matches. You win $0.” | |
| End If | |
| // Update total winnings | |
| Set totalWon = totalWon + amountWon | |
| // Ask if the player wants to play again | |
| Display “Do you want to play again?” | |
| Display “(Enter y for yes.)” | |
| Input playAgain | |
| While playAgain == “y” OR playAgain == “Y” | |
| // Display total amount of money entered and total amount won | |
| Display “You entered a total of “, currencyFormat(totalEntered), | |
| Display “into the slot machine.” | |
| Display “You won a total of “, currencyFormat(totalWon), “!” | |
| End Module | |
| Function DisplaySymbol(Integer symbol) | |
| Switch symbol | |
| Case 1: | |
| Display “Cherries” | |
| Case 2: | |
| Display “Oranges” | |
| Case 3: | |
| Display “Plums” | |
| Case 4: | |
| Display “Bells” | |
| Case 5: | |
| Display “Melons” | |
| Default: | |
| Display “Bars” | |
| End Switch | |
| End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment