c Programming Project
c Programming Project
Wddddddddddddddddddddddddd
1
THEORY
Creating a Rock-Paper-Scissors Game in C
1. Introduction
Rock (✊)
Paper (✋)
Scissors (✌️)
Game Logic
2
Random Number Generation
Syntax:
3
c
#include <unistd.h>
unsigned int sleep(unsigned int seconds);
4
Source code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
int main() {
int playerChoice, computerChoice, rounds, i, playAgain;
int playerScore, computerScore, ties, totalWins = 0,
totalLosses = 0;
srand(time(0));
do {
playerScore = computerScore = ties = 0;
5
printf("\nRound %d\n", i);
printf("1. Rock\n2. Paper\n3. Scissors\n");
printf("Enter your choice (1-3): ");
scanf("%d", &playerChoice);
computerChoice = rand() % 3 + 1;
printf("\nRock... ");
Sleep(500);
printf("Paper... ");
Sleep(500);
printf("Scissors... GO!\n");
Sleep(500);
6
Sleep(500);
if (playerChoice == computerChoice) {
printf("It's a tie!\n");
ties++;
} else if ((playerChoice == 1 && computerChoice == 3)
||
(playerChoice == 2 && computerChoice == 1) ||
(playerChoice == 3 && computerChoice == 2)) {
printf("You win this round!\n");
playerScore++;
} else {
printf("You lose this round!\n");
computerScore++;
}
}
7
totalLosses++;
} else {
printf("It's a tie overall!\n");
}
return 0;
}
OUTPUT
Welcome to Rock, Paper, Scissors!
How many rounds do you want to play? 5
Round 1
1. Rock
2. Paper
3. Scissors
Enter your choice (1-3): 2
8
Rock... Paper... Scissors... GO!
Round 2
1. Rock
2. Paper
3. Scissors
Enter your choice (1-3): 1
Round 3
1. Rock
2. Paper
3. Scissors
Enter your choice (1-3): 3
9
Computer chose: Scissors
It's a tie!
Round 4
1. Rock
2. Paper
3. Scissors
Enter your choice (1-3): 2
Round 5
1. Rock
2. Paper
3. Scissors
Enter your choice (1-3): 3
10
Game Over! Here are the results:
You won: 2 rounds
Computer won: 1 rounds
Tied rounds: 2
Congratulations! You won the game!
Round 1
1. Rock
2. Paper
3. Scissors
Enter your choice (1-3): 2
Round 2
1. Rock
11
2. Paper
3. Scissors
Enter your choice (1-3): 1
Round 3
1. Rock
2. Paper
3. Scissors
Enter your choice (1-3): 2
12
Total Wins: 2 | Total Losses: 0
13
Conclusion of the Rock, Paper, Scissors Program
The Rock, Paper, Scissors game implemented in C is a
simple yet engaging program that demonstrates fundamental
programming concepts such as conditional statements,
loops, random number generation, and user input
handling.
🔹 Key Takeaways
🔹 Future Improvements
14