]> git repositories - atm-program-in-c.git/commitdiff
first commit main
authorbochard <mail@tenkyuu.dev>
Wed, 25 Jun 2025 03:01:50 +0000 (11:01 +0800)
committerbochard <mail@tenkyuu.dev>
Wed, 25 Jun 2025 03:01:50 +0000 (11:01 +0800)
README.md [new file with mode: 0644]
main.c [new file with mode: 0644]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..7d28330
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+### ATM Machine in C
+
+another practice project using C programming language.
\ No newline at end of file
diff --git a/main.c b/main.c
new file mode 100644 (file)
index 0000000..0520ce3
--- /dev/null
+++ b/main.c
@@ -0,0 +1,78 @@
+#include <stdio.h>
+
+void checkBalance(float balance);
+float deposit();
+float withdraw(float balance);
+
+int main(){
+  int choice = 0;
+  float balance = 0.0f;
+
+  printf("*** ATM MACHINE ***\n");
+  printf("beep boop...\n");
+
+  do{
+    printf("\nSelect one option below:\n");
+    printf("\t1-->Check Balance\n");
+    printf("\t2-->Deposit Money\n");
+    printf("\t3-->Withdraw Money\n");
+    printf("\t4-->Exit\n");
+    printf("\nEnter your choice: ");
+    scanf("%d", &choice);
+
+    switch(choice){
+      case 1:
+        checkBalance(balance);
+        break;
+      case 2:
+        balance += deposit();
+        break;
+      case 3:
+        balance -= withdraw(balance);
+        break;
+      case 4:
+        printf("\nbeep boop...bye!\n");
+        break;
+      default:
+        printf("\nbeep boop...invalid choice!\n");
+    }
+  }while(choice != 4);
+
+  return 0;
+}
+
+void checkBalance(float balance){
+  printf("\nYour current balance is: $%.2f\n", balance);
+};
+
+float deposit(){
+  float amount = 0.0f;
+
+  printf("\nEnter amount to deposit: $");
+  scanf("%f", &amount);
+
+  if(amount < 0){
+    printf("Invalid amount\n");
+  }else{
+    printf("Successfully deposited $%.2f\n", amount);
+    return amount;
+  }
+};
+
+float withdraw(float balance){
+  float amount = 0.0f;
+
+  printf("\nEnter the amount to withdraw: $");
+  scanf("%f", &amount);
+
+  if(amount < 0){
+    printf("Invalid amount\n");
+    return 0.0f;
+  }else if(amount > balance){
+    printf("Insufficient funds! Your current balance is $%.2f\n", balance);
+    return 0.0f;
+  }else{
+    printf("Succesfully withdrew $%.2f\n", amount);
+    return amount;
+  }
+};
\ No newline at end of file