Link to home
Start Free TrialLog in
Avatar of neverenough
neverenoughFlag for United States of America

asked on

C# question ....

Hi, I'm pretty new to C# and I'm trying to get this code to work correctly.
After making the initial deposit, if i went ahead and made other deposits and checked the balance, it doesn't work  - it doesn't update.


Please help?

TB
using System;
using System.Collections.Generic;
using System.Text;
 
namespace banking_program
{
    class customer
    {
        //constructor
        customer()
        {
            
            Console.WriteLine("Please Input Your Name :");
            clientName = Console.ReadLine();
 
 
 
            Console.WriteLine("Please Input Your Account Number :");
            accountNum = int.Parse(Console.ReadLine());
            Console.WriteLine();
            Console.WriteLine("Welcome {0}, You have successfully logged into your Account.", clientName);
            Console.WriteLine();
            Console.WriteLine ("Please Enter Your Initial Deposit Amount :");
            startBalance = double.Parse (Console.ReadLine ());
            Console.WriteLine();
            // Console.WriteLine("Welcome {0}, You have successfully logged into your Account",clientName);
            Console.WriteLine();
            accountBal = startBalance;
            totalDeposits = 0;
            totalWithdrawals =0;
        }
        //methods
        public static void calcDeposit(double deposit)
        {
            accountBal = accountBal + totalDeposits;
            totalDeposits = deposit + totalDeposits;
        }
 
        public static void calcWithdrawal(double withDrawal)
        {
            if (accountBal > withDrawal)
            {
                accountBal = accountBal - withDrawal;
                totalWithdrawals = withDrawal + totalWithdrawals;
            }
            else Console.WriteLine("You do not have sufficient funds !!!");
            }
        public static void Balance() 
        { 
            Console.WriteLine("Your Account Balance is: " + accountBal); 
        }
        public static void Main(string[] args)
        {
            int choice;
            double deposit, withdrawal;
            bool dec = true;
            customer account = new customer();
            while (dec)
            {
                Console.WriteLine("Please Select a Transction Type:");
                Console.WriteLine("********************************");
                Console.WriteLine("\n 1 To Make a Deposit\n 2 For Withdrawal\n 3 For Balance Inquiry\n 9 To Terminate The Session:\n ");
                choice = int.Parse(Console.ReadLine());
 
                switch (choice)
                {
                    case 1:
                        Console.WriteLine("What is the Amount of Your Deposit ?");
                        deposit = double.Parse(Console.ReadLine());
                        calcDeposit(deposit);
                                                
                        break;
                  
 
                    case 2:
                        Console.WriteLine("What is the Amount you would like to Withdraw ?");
                        withdrawal = double.Parse(Console.ReadLine());
                        calcWithdrawal(withdrawal);
 
 
                        break;
 
 
                    case 3:
               
                        Balance();
 
                        break;
 
                    case 9:
                        Console.WriteLine("Customer Name: " + clientName);
                        Console.WriteLine("Customer ID: " + accountNum);
                        Console.WriteLine("Starting Balance: " + startBalance); 
 
                        Console.WriteLine("Total Deposits: " + totalDeposits);
                        Console.WriteLine("Total Withdrawals: " + totalWithdrawals);
 
                        Console.WriteLine("Closing Balance: " + accountBal);
                        dec = false;
 
                        
                        break;
 
                        
                }
            
            }
        }
        // Atributes 
 
            static string clientName;
            static int accountNum;
            static double startBalance;
            static double accountBal;
            static double totalDeposits;
            static double totalWithdrawals;
            
 
 
    
 
    }
 
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of neverenough

ASKER

Thanks Fernando !   worked like a charm!
sorry I'm new to this.
Not a problem, glad to help.  ;=)
I awarded you 500 points but i got a wired error message. Can you check? I may have messed up.
let me know...
Everything is fine. Thanks; Fernando