#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

// Function to roll a six-sided die
int rollDie() {
    return rand() % 6 + 1;
}

// Function to play a round of Craps
int playCraps() {
    int die1 = rollDie();
    int die2 = rollDie();
    int sum = die1 + die2;

    printf("You rolled: %d + %d = %d\n", die1, die2, sum);

    if (sum == 7 || sum == 11) {
        printf("Congratulations! You win!\n");
        return 1;  // Win
    } else if (sum == 2 || sum == 3 || sum == 12) {
        printf("Sorry, you lose. Better luck next time.\n");
        return -1;  // Lose
    } else {
        printf("Point established: %d\n", sum);
        printf("Rolling again...\n");

        int point = sum;
        do {
            die1 = rollDie();
            die2 = rollDie();
            sum = die1 + die2;

            printf("You rolled: %d + %d = %d\n", die1, die2, sum);

            if (sum == point) {
                printf("Congratulations! You rolled the point. You win!\n");
                return 1;  // Win
            } else if (sum == 7) {
                printf("Sorry, you rolled a 7. You lose.\n");
                return -1;  // Lose
            }
        } while (1);
    }
}

int main() {
    srand(time(NULL));  // Seed for random number generation

    printf("Welcome to Craps!\n");

    while (1) {
        printf("Press Enter to roll the dice. Type 'exit' to end: ");
        char input[10];
        fgets(input, sizeof(input), stdin);

        if (strcmp(input, "exit\n") == 0) {
            break;  // Exit the loop if the user types 'exit'
        }

        // Play a round of Craps
        int result = playCraps();

        if (result == 1) {
            printf("You won!\n");
        } else if (result == -1) {
            printf("You lost.\n");
        }
    }

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

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: