Hand cricket
Code explanation:
The user starts by choosing "odd" or "even," and then enters a number from 1 to 6. The computer randomly generates a number from 1 to 6, and the sum of the two numbers is used to determine the winner of the toss.
If the sum is even and the player chose "even," the player chooses whether to bat or bowl first.
If the sum is odd and the player chose "odd," the player chooses whether to bat or bowl first.
If the player wins the toss and chooses to bat first, the program asks the user to input a number from 1 to 6. The computer randomly generates a number from 1 to 6, and the sum of the two numbers is added to the player's score.
The player can continue to input numbers until they are out or until their score exceeds the computer's score (if the computer bats second). If the player wins the toss and chooses to bowl first, the program asks the user to input a number from 1 to 6. The computer randomly generates a number from 1 to 6, and the sum of the two numbers is added to the computer's score.
The player can continue to input numbers until the computer is out or until the computer's score exceeds the player's score (if the computer bats second).
Conclusion:
The program uses several functions to simulate the game, including functions for the player batting, the player bowling, and functions for the computer winning or losing the toss. The program could also benefit from additional error checking and better organization.
Click here to download source code.
For better results run the code in codeblocks or cxxdroid(for android).
Comments
Post a Comment