google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Sunday, March 30, 2025

C program that simulates a basic indoor game, "Treasure Hunt".

 Here's a simplified C program that simulates a basic indoor game, "Treasure Hunt".


Treasure Hunt Game


#include <stdio.h>

#include <stdlib.h>

#include <time.h>


// Define structure for rooms

typedef struct {

    char name[50];

    char description[100];

    int treasure;

} Room;


// Define structure for players

typedef struct {

    char name[50];

    int score;

} Player;


// Function to create a new room

Room createRoom(char *name, char *description, int treasure) {

    Room room;

    strcpy(room.name, name);

    strcpy(room.description, description);

    room.treasure = treasure;

    return room;

}


// Function to create a new player

Player createPlayer(char *name) {

    Player player;

    strcpy(player.name, name);

    player.score = 0;

    return player;

}


// Function to play the game

void playGame(Room *rooms, int roomCount, Player *player) {

    int currentRoom = 0;

    while (1) {

        printf("\nYou are in the %s.\n", rooms[currentRoom].name);

        printf("%s\n", rooms[currentRoom].description);

        printf("Do you want to:\n1. Move to the next room\n2. Search for treasure\n3. Quit the game\n");

        int choice;

        scanf("%d", &choice);

        switch (choice) {

            case 1:

                if (currentRoom < roomCount - 1) {

                    currentRoom++;

                } else {

                    printf("You are already in the last room!\n");

                }

                break;

            case 2:

                if (rooms[currentRoom].treasure) {

                    printf("You found treasure! Your score increases by 10 points.\n");

                    player->score += 10;

                } else {

                    printf("There is no treasure in this room!\n");

                }

                break;

            case 3:

                printf("Thanks for playing! Your final score is %d.\n", player->score);

                return;

            default:

                printf("Invalid choice! Please choose again.\n");

        }

    }

}


int main() {

    // Create rooms

    Room room1 = createRoom("Room 1", "This is the first room.", 1);

    Room room2 = createRoom("Room 2", "This is the second room.", 0);

    Room room3 = createRoom("Room 3", "This is the third room.", 1);

    Room rooms[] = {room1, room2, room3};

    int roomCount = sizeof(rooms) / sizeof(rooms[0]);


    // Create player

    char playerName[50];

    printf("Enter your name: ");

    scanf("%s", playerName);

    Player player = createPlayer(playerName);


    // Play the game

    playGame(rooms, roomCount, &player);


    return 0;

}



This program demonstrates the following concepts:


1. *Room structure*: A structure to represent rooms with attributes like name, description, and treasure.

2. *Player structure*: A structure to represent players with attributes like name and score.

3. *Gameplay*: A function to simulate the gameplay, where the player navigates through rooms, searches for treasure, and earns points.


Note that this program is a highly simplified example and does not cover real-world complexities like game design, user input handling, and scoring systems.

C program that simulates a kirana store's billing system

 Here's a simplified C program that simulates a kirana store's billing system:


Kirana Store Billing Program


#include <stdio.h>

#include <stdlib.h>


// Define structure for products

typedef struct {

    char name[50];

    float retailRate;

    float wholesaleRate;

    int quantity;

} Product;


// Define structure for bills

typedef struct {

    Product product;

    float rate;

    int quantity;

    float amount;

} Bill;


// Function to create a new product

Product createProduct(char *name, float retailRate, float wholesaleRate, int quantity) {

    Product product;

    strcpy(product.name, name);

    product.retailRate = retailRate;

    product.wholesaleRate = wholesaleRate;

    product.quantity = quantity;

    return product;

}


// Function to create a new bill

Bill createBill(Product product, float rate, int quantity) {

    Bill bill;

    bill.product = product;

    bill.rate = rate;

    bill.quantity = quantity;

    bill.amount = rate * quantity;

    return bill;

}


// Function to display bill details

void displayBill(Bill bill) {

    printf("Product Name: %s\n", bill.product.name);

    printf("Rate: %.2f\n", bill.rate);

    printf("Quantity: %d\n", bill.quantity);

    printf("Amount: %.2f\n", bill.amount);

}


// Function to calculate total profit

float calculateProfit(Bill *bills, int billCount) {

    float totalProfit = 0;

    for (int i = 0; i < billCount; i++) {

        if (bills[i].rate == bills[i].product.wholesaleRate) {

            totalProfit += (bills[i].product.retailRate - bills[i].product.wholesaleRate) * bills[i].quantity;

        }

    }

    return totalProfit;

}


int main() {

    // Create products

    Product product1 = createProduct("Rice", 50.0, 40.0, 100);

    Product product2 = createProduct("Wheat", 30.0, 25.0, 50);


    // Create bills

    Bill bill1 = createBill(product1, 50.0, 20);

    Bill bill2 = createBill(product2, 25.0, 30);

    Bill bill3 = createBill(product1, 40.0, 50); // Wholesale rate


    // Display bill details

    printf("Bill 1:\n");

    displayBill(bill1);

    printf("\nBill 2:\n");

    displayBill(bill2);

    printf("\nBill 3:\n");

    displayBill(bill3);


    // Calculate total profit

    Bill bills[] = {bill1, bill2, bill3};

    float totalProfit = calculateProfit(bills, 3);

    printf("\nTotal Profit: %.2f\n", totalProfit);


    return 0;

}



This program demonstrates the following concepts:


1. *Product structure*: A structure to represent products with attributes like name, retail rate, wholesale rate, and quantity.

2. *Bill structure*: A structure to represent bills with attributes like product, rate, quantity, and amount.

3. *Billing system*: A system to create bills based on product rates and quantities.

4. *Profit calculation*: A function to calculate the total profit earned by selling products at retail and wholesale rates.


Note that this program is a highly simplified example and does not cover real-world complexities like inventory management, customer management, and tax calculations.

Crude drugs in pharmacognosy

 In pharmacognosy, crude drugs refer to plant or animal materials that are used in their natural or minimally processed form to produce ther...