Course Content
Detailed Content of Programming in C
0/1
Introduction
0/1
Structure of C program
0/1
Answers of ‘C’ Pointers Programs
0/1
About Lesson

Design a basic banking system that allows users to deposit, withdraw, and check their balance. Use appropriate data types and operators for the transactions.

#include <stdio.h>

int main() {
// Declare variables
float balance = 0.0;
int choice;
float amount;

// Display menu
printf(“1. Depositn”);
printf(“2. Withdrawn”);
printf(“3. Check Balancen”);
printf(“Enter your choice (1/2/3): “);
scanf(“%d”, &choice);

// Process: Perform transaction based on user choice
switch (choice) {
case 1:
printf(“Enter the deposit amount: “);
scanf(“%f”, &amount);
balance += amount;
printf(“Deposit successful. Updated balance: %.2fn”, balance);
break;
case 2:
printf(“Enter the withdrawal amount: “);
scanf(“%f”, &amount);
if (amount > balance) {
printf(“Error: Insufficient funds.n”);
} else {
balance -= amount;
printf(“Withdrawal successful. Updated balance: %.2fn”, balance);
}
break;
case 3:
printf(“Current Balance: %.2fn”, balance);
break;
default:
printf(“Error: Invalid choice.n”);
return 1; // Exit the program with an error code
}

return 0; // Exit the program successfully
}