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

// Function to simulate a slot machine spin
void spinSlotMachine(int *symbol1, int *symbol2, int *symbol3) {
    *symbol1 = rand() % 3 + 1;  // Symbol 1 can be 1, 2, or 3
    *symbol2 = rand() % 3 + 1;  // Symbol 2 can be 1, 2, or 3
    *symbol3 = rand() % 3 + 1;  // Symbol 3 can be 1, 2, or 3
}

// Function to determine the win based on the symbols
int determineWin(int symbol1, int symbol2, int symbol3) {
    if (symbol1 == symbol2 && symbol2 == symbol3) {
        // All three symbols are the same
        return 1;  // Win
    } else if (symbol1 == symbol2 || symbol1 == symbol3 || symbol2 == symbol3) {
        // At least two symbols are the same
        return 2;  // Small win
    } else {
        // No matching symbols
        return 0;  // No win
    }
}

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

    int symbol1, symbol2, symbol3;
    int totalWinnings = 0;

    printf("Welcome to the Slot Machine!\n");

    while (1) {
        printf("\nPress Enter to spin the slot machine. 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'
        }

        // Spin the slot machine
        spinSlotMachine(&symbol1, &symbol2, &symbol3);

        // Display the symbols
        printf("Symbols: %d %d %d\n", symbol1, symbol2, symbol3);

        // Determine the win and update total winnings
        int winType = determineWin(symbol1, symbol2, symbol3);
        if (winType == 1) {
            printf("Congratulations! You won the Jackpot!\n");
            totalWinnings += 1000;
        } else if (winType == 2) {
            printf("You won a small prize!\n");
            totalWinnings += 100;
        } else {
            printf("Sorry, no win this time.\n");
        }

        // Display total winnings
        printf("Total Winnings: $%d\n", totalWinnings);
    }

    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: