Cover Image for Cricket Score Sheet in C
62 views

Cricket Score Sheet in C

Creating a cricket score sheet program in C can be a complex task due to the various aspects of cricket scoring, including runs, wickets, overs, and more. Below, I’ll provide a simplified example of how you can create a basic cricket score sheet in C to keep track of runs scored and wickets taken by a team. Please note that this is a minimalistic example and does not cover all aspects of cricket scoring.

C
#include <stdio.h>

int main() {
    int runs = 0;
    int wickets = 0;
    int overs = 0;
    int balls = 0;

    printf("Cricket Score Sheet\n");

    while (1) {
        printf("Current Score: %d/%d\n", runs, wickets);
        printf("Overs: %d.%d\n", overs, balls);

        printf("Enter runs scored in this ball (0-6, -1 for wicket, -2 to exit): ");
        int score;
        scanf("%d", &score);

        if (score == -1) {
            wickets++;
        } else if (score == -2) {
            break;
        } else if (score >= 0 && score <= 6) {
            runs += score;
            balls++;

            if (balls == 6) {
                overs++;
                balls = 0;
            }
        } else {
            printf("Invalid input. Please enter a valid score.\n");
        }
    }

    printf("Final Score: %d/%d\n", runs, wickets);
    printf("Overs: %d.%d\n", overs, balls);

    return 0;
}

In this basic cricket score sheet program:

  1. The program initializes variables to keep track of runs, wickets, overs, and balls.
  2. It enters an infinite loop to accept input for each ball bowled.
  3. The user can input runs scored in each ball (0-6), mark a wicket (-1), or exit the program (-2).
  4. Runs are added to the total, and if a wicket is marked, the wickets count is incremented.
  5. Overs are incremented after every 6 balls.
  6. Invalid input is handled with a message.
  7. The loop exits when -2 is entered, and the final score and overs are displayed.

Please note that this is a basic example for educational purposes and does not cover all the complexities of a real cricket score sheet, such as recording individual batsman statistics, bowler details, fielding positions, and more. Real cricket score sheets are typically more comprehensive and structured.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS