Using srand() and rand() function in C, a simple but interesting game can be made. This game is called “Guess Game” .
Rules of the Game :
- There are three holes . A rat is hidden in one of those three holes.
- The Rat shuffles its position every time.
- You have to guess the hole in which the Rat is hidden among the three holes.
- The hole in which Rat is present is named as ‘R’ and rest two are named as ‘N’.
- You have some cash(inhand_cash) with you.
- You make a bet (amount_bet) for playing this game every time you make a guess.
- If your guess is wrong, you loose the amount_bet from your inhand_cash.
- If you guess is right, you win twice the amount_bet in your inhand_cash.
- Keep playing and keep winning until you go out of cash.
Below is the code in C for this simple and interesting game:
Note : As this game takes input from the players for their inhand_cash, bet_amount and the guessed location of the rat, so this will not run in online compiler.
Note: This output is not taken from online compiler
----Enter the inhand_cash you have right now---- : 1 Enter the amount_bet you want to play for : 1 Wait !! Rat is shuffling its position... You may now guess the hole in which Rat is present: 1 You Loose ! The holes are as follows: "N N R" Your inhand_cash is now = 0 " :-( Sorry you don't have enough cash to play more, Do come next time" Thank You for playing :-)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- rand() and srand() in C/C++
- Output of C programs | Set 33 (rand() and srand())
- The prisoner's dilemma in Game theory
- OpenGL program for Simple Ball Game
- Variation in Nim Game
- Check if the game is valid or not
- Python | Program to implement simple FLAMES game
- Design Snake Game
- How to Get Started with Game Development?
- Python | Pokémon Training Game
- Tips For an Indie Game Developer
- Number guessing game in Python 3
- Introduction to pyglet library for game development in Python
- Getting System and Process Information Using C Programming and Shell in Linux
- Count number of unique Triangles using STL | Set 1 (Using set)
- Print substring of a given string without using any string function and loop in C
- std::tuple, std::pair | Returning multiple values from a function using Tuple and Pair in C++
- Inline namespaces and usage of the "using" directive inside namespaces
- GET and POST requests using Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.