Final term project on C Language To lecturer Aaron By Aqib, Shimanto and Nafis
The project explained In this project, we built a simple game of Rock, Papers and Scissors The winner of the game is decided as per the below rules: Rock vs Paper -> Paper wins. Rock vs Scissor -> Rock wins. Paper vs Scissor -> Scissor wins.
Input and Output
Output: Firstly the user will be asked about the choice:
When the user enters the choice then the result is displayed:-
1. necessary libraries:- These lines include the necessary libraries for the program to function. math.h is included for mathematical operations, stdio.h is for input/output functions, stdlib.h is for general utility functions, and time.h is for time-related functions. Explaining the code
Explaining the code 2. Define the “game” function:- This function takes two character parameters: ‘ you’ (representing the user's choice) and ‘ computer’ (representing the computer's choice). It returns an integer value based on the outcome of the game.
Explaining the code 3. Implement the game logic:- This function takes two character parameters: ‘you’ (representing the user's choice) and ‘computer’ (representing the computer's choice). It returns an integer value based on the outcome of the game. * -1 if the game is a draw * 0 if the user loses * 1 if the user wins
4. Define the “ main” function:- These lines include the necessary libraries for the program to function. math.h is included for mathematical operations, stdio.h is for input/output functions, stdlib.h is for general utility functions, and time.h is for time-related functions.
Continued:- The ‘main’ function is the entry point of the program. It generates a random number using ‘ srand(time(NULL))’ and ‘ rand() % 100” to determine the computer's choice. The user is prompted to enter their choice, and the “ game’ function is called with the user's and computer's choices. Finally, the result is displayed based on the value returned by the game function. The program uses character variables 's' , 'p' , and ' z' to represent stone, paper, and scissors, respectively. Overall, this C program implements a simple Rock, Paper, Scissors game where the user plays against the computer. The computer's choice is randomly generated, and the winner is determined based on the rules of the game.