C Online Compiler
Example: Bank Cash Withdrawal in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Bank Cash Withdrawal #include <stdio.h> int main() { float balance; // Variable to store the current account balance float withdrawalAmount; // Variable to store the amount to be withdrawn // Step 1: Prompt user for initial account balance printf("Enter current account balance: "); scanf("%f", &balance); // Step 2: Prompt user for the amount to withdraw printf("Enter amount to withdraw: "); scanf("%f", &withdrawalAmount); // Step 3: Check if the withdrawal amount is valid (positive) if (withdrawalAmount <= 0) { printf("Invalid withdrawal amount. Please enter a positive value.\n"); } // Step 4: Check if there are sufficient funds else if (withdrawalAmount <= balance) { // Perform the withdrawal balance -= withdrawalAmount; printf("Withdrawal successful!\n"); printf("Remaining balance: $%.2f\n", balance); } // Step 5: Handle insufficient funds else { printf("Insufficient funds.\n"); printf("Current balance: $%.2f\n", balance); } return 0; }
Output
Clear
ADVERTISEMENTS