Thread: bank program not subtracting from account when i choose withdraw

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    1

    bank program not subtracting from account when i choose withdraw

    i have created a bank program with a do while loop switch statement and functions. everything works except when i choose to withdraw it isnt subtracting instead its giving me my account balance without taking out the withdrawal can anyone suggest why?


    Code:
     #include <stdio.h>
    
                char displaymenu();
                float getdeposit(float balance);
                float  getwithdrawal(float balance);
                void displaybalance(float );
    
    
                   int main()
                {
    
                    char  choice;
                    char  transaction='y';
                    float deposit=0;
                    float withdrawal;
                    float balance;
                  
    
    
                  do  {
                    choice=displaymenu();    
                
    
    
                     switch (choice)
                   {
                       
                         
                        case 'd':case 'D':
                           
                           balance=getdeposit(balance);  
                            break;
    
                         case 'w':case 'W':
                                   withdrawal=getwithdrawal(balance); 
                                 break;
                        
                           case 'b':case 'B':
                             printf("Checking your account balance\n");
                             displaybalance(balance);
                             break;
    
                         case 'q':case 'Q':
                           printf("Quit\n");
                           printf("Thankyou");
                            break;
    
                           default:
                           printf("Invalid Choice\n");
                       
                       
                       
                       
                       
                       
                   }
                    printf("\n\n\n DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): \n");
                               scanf(" %c",&transaction);
                   
                       }while
                   
                      (transaction == 'y'|| transaction == 'Y');
                   
                   
                    return 0;
                 }
                 
                 char displaymenu()
                 {
                     
                         char choice;
    
    
    
                          printf("Welcome to Federal Credit Union!\n");
                          printf("Please select from the following menu\n");
                          printf("d. Make a deposit\n");
                          printf("w. Make a withdrawal\n");
                          printf("b. check balance\n");
                          printf("q. Quit\n");
                          scanf ("\n%c",&choice);
                          return choice;
                     
                     
                 
                 }
                 
                  float getdeposit(float balance)
                 {
                     
                     float deposit;
                          printf("How much would you like to deposit?\n");
                         scanf ("%f",&deposit);
                        balance=deposit+balance;
                        return balance;
                     
                 }
                 float  getwithdrawal(float balance)
                 {
                     
                       float withdrawal;
                      printf("How much would you like to withdraw?\n");
                      scanf ("%f",&withdrawal);
                       balance=balance-withdrawal;
                       return balance;
                     
                 }
                void displaybalance(float balance)
                 {
                      printf("Your balance is %.2f\n",balance);
                     
                 }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,703
    Compare the assignments.
    balance=getdeposit(balance);
    vs.
    withdrawal=getwithdrawal(balance);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bank Account Program
    By shawnc30075 in forum C Programming
    Replies: 1
    Last Post: 04-13-2011, 04:31 PM
  2. Bank Account Problem
    By JayBlay77 in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2009, 08:41 AM
  3. Bank Account Program
    By ace96320 in forum C++ Programming
    Replies: 2
    Last Post: 07-06-2008, 03:26 AM
  4. bank account program
    By JJH35 in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2006, 06:05 PM
  5. Bank Account
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 09-14-2003, 02:27 AM

Tags for this Thread