0% found this document useful (0 votes)
7 views3 pages

c program

The document is a C program that implements a simple bank transaction system. It allows users to check their balance, deposit money, withdraw money, and exit the program, with input validation for each operation. The program runs in an infinite loop until the user chooses to exit, ensuring a user-friendly experience.

Uploaded by

Saripilli Vasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

c program

The document is a C program that implements a simple bank transaction system. It allows users to check their balance, deposit money, withdraw money, and exit the program, with input validation for each operation. The program runs in an infinite loop until the user chooses to exit, ensuring a user-friendly experience.

Uploaded by

Saripilli Vasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>

#include <stdlib.h>

// Function to display the menu

void displayMenu() {

printf("\n--- Bank Transaction Menu ---\n");

printf("1. Check Balance\n");

printf("2. Deposit Money\n");

printf("3. Withdraw Money\n");

printf("4. Exit\n");

printf("Please select an option (1-4): ");

int main() {

float balance = 1000.0; // Initial balance

int choice;

float amount;

// Infinite loop to handle user choices

while (1) {

// Display the menu

displayMenu();

// Read user choice

if (scanf("%d", &choice) != 1) {

// If the input is not an integer, clear the buffer and ask again

printf("Invalid input. Please enter a number between 1 and 4.\n");

while(getchar() != '\n'); // Clear the buffer

continue;

}
// Handle the user's choice using a switch-case

switch (choice) {

case 1:

// Display current balance

printf("Your current balance is: $%.2f\n", balance);

break;

case 2:

// Deposit money

printf("Enter the amount to deposit: $");

if (scanf("%f", &amount) != 1) {

printf("Invalid input! Please enter a valid amount.\n");

while(getchar() != '\n'); // Clear the buffer

break;

if (amount > 0) {

balance += amount;

printf("You have successfully deposited $%.2f.\n", amount);

printf("Your new balance is: $%.2f\n", balance);

} else {

printf("Invalid amount! Please enter a positive value.\n");

break;

case 3:

// Withdraw money

printf("Enter the amount to withdraw: $");

if (scanf("%f", &amount) != 1) {

printf("Invalid input! Please enter a valid amount.\n");

while(getchar() != '\n'); // Clear the buffer

break;

if (amount > 0 && amount <= balance) {


balance -= amount;

printf("You have successfully withdrawn $%.2f.\n", amount);

printf("Your new balance is: $%.2f\n", balance);

} else if (amount > balance) {

printf("Insufficient balance! Your current balance is: $%.2f\n", balance);

} else {

printf("Invalid amount! Please enter a positive value.\n");

break;

case 4:

// Exit the program

printf("Thank you for using our banking system. Goodbye!\n");

exit(0);

default:

printf("Invalid option! Please select a valid option (1-4).\n");

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy