All Projects

Bus Ticket Booking System in Python
Bus Ticket Booking System in Java
Bus Ticket Booking System in Cpp
Bus Ticket Booking System in C
Cafe Order System in Python
Cafe Order System in Java
Cafe Order System in Cpp
Cafe Order System in C
Social Media Account Details Manager in Python
Social Media Account Details Manager in Java
Social Media Account Details Manager in Cpp
Social Media Account Details Manager in C
Mini ATM in Python Language
Mini ATM in Java Language
Mini ATM in cpp language
Mini ATM in c language
Pocket Money Manager in Python Language
Pocket Money Manager in Java Language
Pocket Money Manager in Cpp Language
Pocket Money Manager in C Language
Username Password Generator in Python Language
Username Password Generator in Cpp Language
Username Password Generator in C Language
Telephone Directory in Python Language
Telephone Directory in Java Language
Telephone Directory in Cpp Language
Telephone Directory in C Language
Calander in Cpp Language
Calander in C Language
NoteBook in Python Language
NoteBook in Cpp Language
NoteBook in C Language
Voting System in Python Language
Voting System in Java Language
Voting System in Cpp Language
Voting System in C Language
Age Calculator in Python Language
Age Calculator in Java Language
Age Calculator in Cpp Language
Age Calculator in C Language
Currency Converter in Python Language
Currency Converter in Java Language
Currency Converter in Cpp Language
Currency Converter in C Language
Random Password Generator in python language
Random Password Generator in java language
Random Password Generator in cpp language
Random Password Generator in c language
Billing System in python language
Billing System in c++ language
Billing System in c language
Atm in c language

Pocket Money Manager in C Language


Aniket The Programmer

1.22K+ Subscribers

Click To Subscribe My Channel

Subscribe

Source Code

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

struct Transaction {
    char description[100];
    float amount;
};

struct PocketMoney {
    float budget;
    float expenses;
    float savings;
    struct Transaction transactions[100];
    int transactionCount;
};

void initialize(struct PocketMoney *pocket) {
    printf("Enter your budget for the month: ");
    scanf("%f", &pocket->budget);
    pocket->expenses = 0.0;
    pocket->savings = 0.0;
    pocket->transactionCount = 0;
}

void spend(struct PocketMoney *pocket) {
    float amount;
    printf("Enter amount spent: ");
    scanf("%f", &amount);
    if (amount <= pocket->budget - pocket->expenses) {
        pocket->expenses += amount;
        printf("Expense recorded.");
        printf("Enter a brief description for this expense: ");
        getchar(); // Clear newline from buffer
        fgets(pocket->transactions[pocket->transactionCount].description, sizeof(pocket->transactions[pocket->transactionCount].description), stdin);
        pocket->transactions[pocket->transactionCount].amount = amount;
        pocket->transactionCount++;
    } else {
        printf("Exceeds the budget! Cannot spend more.");
    }
}

void save(struct PocketMoney *pocket) {
    float amount;
    printf("Enter amount saved: ");
    scanf("%f", &amount);
    if (amount <= pocket->expenses) {
        pocket->savings += amount;
        pocket->expenses -= amount;
        printf("Savings recorded.");
        printf("Enter a brief description for this savings: ");
        getchar(); // Clear newline from buffer
        fgets(pocket->transactions[pocket->transactionCount].description, sizeof(pocket->transactions[pocket->transactionCount].description), stdin);
        pocket->transactions[pocket->transactionCount].amount = -amount; // Negative amount denotes savings
        pocket->transactionCount++;
    } else {
        printf("Cannot save more than expenses!");
    }
}

void display(struct PocketMoney *pocket) {
    printf("Pocket Money Management:");
    printf("----------------------------");
    printf("Budget: %.2f", pocket->budget);
    printf("Expenses: %.2f", pocket->expenses);
    printf("Savings: %.2f", pocket->savings);
    printf("----------------------------");
}

void showTransactions(struct PocketMoney *pocket) {
    printf("Transactions History:");
    printf("----------------------------");
    for (int i = 0; i < pocket->transactionCount; ++i) {
        printf("Description: %sAmount: %.2f", pocket->transactions[i].description, pocket->transactions[i].amount);
    }
    printf("----------------------------");
}

void setReminder() {
    // Function to set a reminder for the end of the month
    time_t now;
    struct tm endOfMonth;
    time(&now);
    endOfMonth = *localtime(&now);

    endOfMonth.tm_mon += 1; // Increase month by 1
    endOfMonth.tm_mday = 1; // Set day to the first day of next month
    endOfMonth.tm_hour = 0; // Set time to midnight
    endOfMonth.tm_min = 0;
    endOfMonth.tm_sec = 0;

    mktime(&endOfMonth); // Normalize the time structure

    printf("Reminder: Reset the budget by the end of the month!");
    printf("The end of the month is on: %s", asctime(&endOfMonth));
}

int main() {
    struct PocketMoney pocket;
    int choice;

    initialize(&pocket);

    do {
        printf("Pocket Money Menu:");
        printf("1. Spend Money");
        printf("2. Save Money");
        printf("3. Display Details");
        printf("4. Show Transactions");
        printf("5. Set Reminder");
        printf("6. Exit");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                spend(&pocket);
                break;
            case 2:
                save(&pocket);
                break;
            case 3:
                display(&pocket);
                break;
            case 4:
                showTransactions(&pocket);
                break;
            case 5:
                setReminder();
                break;
            case 6:
                printf("Exiting...");
                break;
            default:
                printf("Invalid choice. Please enter a valid option.");
        }
    } while (choice != 6);

    return 0;
}
        
    

Source Code Github Link: View

View Video On Youtube Link: View

35k+ Coding Problems: Edocgram is collection of 35k+ coding problems Edocgram! 🎉