Welcome to the tutorial on how to create a digital Ping Pong Scoreboard using the C++ programming language. The scoreboard will display the points scored by each player and track the score throughout the game.

Objective

The goal of this project is to build a digital scoreboard that will track and display the scores of two players in a ping pong game. The program will:

  • Initialize both players’ scores to 0.
  • Allow for score input through a simple interface.
  • Display the updated scores after each point.
  • End the game when a player reaches a predefined winning score.

Code Implementation

#include 
using namespace std;

// Function to display the current scoreboard
void displayScore(int player1Score, int player2Score) {
    cout << "\n----------------------------" << endl;
    cout << "Player 1: " << player1Score << " | Player 2: " << player2Score << endl;
    cout << "----------------------------" << endl;
}

int main() {
    int player1Score = 0, player2Score = 0;
    int winningScore = 11; // Standard ping pong game winning score
    int player1Points, player2Points;

    cout << "Welcome to the Ping Pong Game!" << endl;
    cout << "First player to reach " << winningScore << " points wins!" << endl;

    // Main game loop
    while (player1Score < winningScore && player2Score < winningScore) {
        displayScore(player1Score, player2Score);

        // Input for player 1
        cout << "\nEnter points for Player 1: "; cin >> player1Points;
        player1Score += player1Points;

        // Input for player 2
        cout << "Enter points for Player 2: "; cin >> player2Points;
        player2Score += player2Points;

        if (player1Score >= winningScore || player2Score >= winningScore) {
            break;
        }
    }

    // Display final result
    displayScore(player1Score, player2Score);

    if (player1Score >= winningScore) {
        cout << "Player 1 wins!" << endl; } else if (player2Score >= winningScore) {
        cout << "Player 2 wins!" << endl;
    }

    return 0;
}

Explanation of the Program

The program is designed to run a simple ping pong game between two players. Here’s how it works:

  1. The program starts by initializing both players’ scores to zero.
  2. It then enters a loop, where it asks for input from both players for the points they scored in a given round.
  3. After each round, the scores are updated and displayed using the displayScore() function.
  4. If either player reaches the defined winning score (11 points), the game ends, and the winner is announced.

How to Run the Program

Follow these steps to run the Ping Pong Scoreboard program:

  1. Make sure you have a C++ compiler installed on your system (e.g., GCC, MinGW, or any IDE like Code::Blocks or Visual Studio).
  2. Create a new C++ file (e.g., ping_pong_scoreboard.cpp) and copy the code into it.
  3. Compile the program using your chosen compiler. For example, in the terminal or command prompt, type:
    • g++ ping_pong_scoreboard.cpp -o ping_pong_scoreboard
  4. Run the program by typing the following command:
    • ./ping_pong_scoreboard
  5. Follow the on-screen prompts to enter points for each player and watch the scoreboard update in real-time.
© 2025 Learn Programming. All rights reserved.

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)