Skip to content

Instantly share code, notes, and snippets.

@markylaredo
Created January 15, 2024 14:33
Show Gist options
  • Save markylaredo/5699af126c8d6f4da088769e48ff00dc to your computer and use it in GitHub Desktop.
Save markylaredo/5699af126c8d6f4da088769e48ff00dc to your computer and use it in GitHub Desktop.
Simple Checkbook Balancer in C
#include <stdio.h>
int main() {
float initial_balance = 0.0;
float current_balance = initial_balance;
float transaction;
printf("Enter deposits and issuances (terminate with 0):\n");
do {
printf("Enter amount: ");
scanf("%f", &transaction);
if (transaction == 0) {
break;
}
if (current_balance + transaction < 0) {
printf("Check bounced! Insufficient funds.\n");
printf("Transaction ignored.\n");
} else {
if (transaction > 0) {
printf("Deposit: $%.2f\n", transaction);
} else {
printf("Issuance: $%.2f\n", -transaction);
}
current_balance += transaction;
printf("Running Balance: $%.2f\n", current_balance);
}
} while (1);
printf("Checkbook balancing complete.\n");
printf("Final Balance: $%.2f\n", current_balance);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment