Skip to main content

Rock, Paper, Scissors game using C programming

 Rock, Paper, Scissors game using C programming:

Program:

#include <stdio.h>

#include <stdlib.h>

#include <time.h>


int main() {

    char choice;

    char userChoice;

    int computerChoice;

    int userScore = 0, computerScore = 0;


    srand(time(NULL)); // Seed the random number generator


    printf("Let's play Rock, Paper, Scissors!\n");

    printf("Enter your choice (R for Rock, P for Paper, S for Scissors):\n");


    while (1) {

        printf("Your choice: ");

        scanf(" %c", &userChoice);


        // Convert user's choice to uppercase

        userChoice = toupper(userChoice);


        // Generate computer's choice (0 for Rock, 1 for Paper, 2 for Scissors)

        computerChoice = rand() % 3;


        // Display computer's choice

        switch (computerChoice) {

            case 0:

                printf("Computer chooses: Rock\n");

                break;

            case 1:

                printf("Computer chooses: Paper\n");

                break;

            case 2:

                printf("Computer chooses: Scissors\n");

                break;

        }


        // Determine the winner

        if (userChoice == 'R') {

            if (computerChoice == 0) {

                printf("It's a tie!\n");

            } else if (computerChoice == 1) {

                printf("Computer wins!\n");

                computerScore++;

            } else {

                printf("You win!\n");

                userScore++;

            }

        } else if (userChoice == 'P') {

            if (computerChoice == 0) {

                printf("You win!\n");

                userScore++;

            } else if (computerChoice == 1) {

                printf("It's a tie!\n");

            } else {

                printf("Computer wins!\n");

                computerScore++;

            }

        } else if (userChoice == 'S') {

            if (computerChoice == 0) {

                printf("Computer wins!\n");

                computerScore++;

            } else if (computerChoice == 1) {

                printf("You win!\n");

                userScore++;

            } else {

                printf("It's a tie!\n");

            }

        } else {

            printf("Invalid choice. Please enter R, P, or S.\n");

            continue; // Restart the loop if the choice is invalid

        }


        // Display scores

        printf("Your score: %d\n", userScore);

        printf("Computer's score: %d\n", computerScore);


        // Ask if the user wants to play again

        printf("Do you want to play again? (Y/N): ");

        scanf(" %c", &choice);


        if (toupper(choice) != 'Y')

            break; // Exit the loop if the user doesn't want to play again

    }


    printf("Thanks for playing!\n");


    return 0;

}

Output:

Let's play Rock, Paper, Scissors!
Enter your choice (R for Rock, P for Paper, S for Scissors):
Your choice: R
Computer chooses: Scissors
You win!
Your score: 1
Computer's score: 0
Do you want to play again? (Y/N): Y
Your choice: P
Computer chooses: Rock
You win!
Your score: 2
Computer's score: 0
Do you want to play again? (Y/N): Y
Your choice: S
Computer chooses: Paper
Computer wins!
Your score: 2
Computer's score: 1
Do you want to play again? (Y/N): N
Thanks for playing!

Comments

Popular posts from this blog

Install TensorFlow on Windows 11: Step-by-Step Guide for CPU & GPU

 --- Installing **TensorFlow on Windows 11** requires setting up system dependencies, configuring Python, and ensuring compatibility with CPU or GPU acceleration. This step-by-step guide provides everything needed to install **TensorFlow 2.10 or lower** on **Windows Native**, including software prerequisites, Microsoft Visual C++ Redistributable installation, Miniconda setup, GPU driver configuration, and verification steps.   ### **System Requirements:**   Before installing TensorFlow, ensure your system meets these requirements:   - **Operating System:** Windows 7 or higher (64-bit)   - **Python Version:** 3.9–3.12   - **pip Version:** 19.0 or higher for Linux and Windows, 20.3 or higher for macOS   - **Microsoft Visual C++ Redistributable:** Required for Windows Native   - **Long Paths Enabled:** Ensure long paths are enabled in Windows settings   For **GPU support**, install:   - **NVIDIA ...

Unreal Engine Product Showcase: Mesmerizing Video Sequence Render

  4k Image:

Cloudflare Is Down Worldwide: What Happened, What It Means & What You Can Do

🌍 Cloudflare Is Down Worldwide: What Happened & Why the Internet Broke Today On 18 November 2025 , the internet experienced one of the largest global outages in years as Cloudflare , the backbone of countless websites and online services, went down unexpectedly. The outage caused millions of websites to become slow, unreachable, or return 5xx internal server errors , leading to widespread disruption across businesses, apps, and essential online platforms. This blog post explains what happened, why the internet broke for many users, and what Cloudflare has officially said so far. What Exactly Happened? Around 4:30 PM IST , reports began flooding social media and outage trackers like Downdetector. Users across India, Europe, the US, and Southeast Asia noticed that: Websites were not loading Requests were timing out Services dependent on Cloudflare CDN or DNS stopped responding APIs hosted through Cloudflare were failing Even some security and protection layers were ...