By RAHUL SHARMA
This is an exciting project, where we will learn about the library used to generate random numbers.
The above game is a simulation of a number game for the learning purpose where we learn how to print a random number using the header file cstdlib. The program asks for a betting amount and then asks the user to guess a number on rolling. If the random number generated matches the user input, he wins and the amount is added to his present amount left, else money is deducted. The user can keep playing until he loses all the amount he put in initially.
The game asks for our name and starting amount.
Then it asks the user to enter the amount for betting and then it shows the winning number and if the guess is wrong then the amount is deducted and if your guess is correct then we get the winning amount added to our balance price and ask the user that would you like to play more.
dice = rand()%10 + 1;
The rand() function generates a random number and we take reminder of it by dividing 10 and adds 1 so that the number generated is between 1 to 10. This is the main learning from the above project.
We can play the game till we have some with us if we do not have any amount we lost the game and we have to start again.