Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
104 views
in Technique[技术] by (71.8m points)

C# Overdraft addition

I'm fairly new to C# and would wonder how you'd go about adding an overdraft to this simple bank menu I've assembled. I'd like to add the current menu if possible.

I assume I'd have ot make a new method to withdraw from 'overDraft' once 'myBalance' had been depleted, which should in theory just be a simple 'else' but I'm not too sure.

Thanks in advance.

  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyBankAccount
{
    class BankAccount 
    {
        static void DisplayBankBal(double myBal)
        {
            Console.WriteLine("Your current bank balance is: £" + myBal);
        }

        static double Deposit(double myBal) 
        {
            Console.WriteLine("How much would you like to deposit?"); 
            double newDepo = Convert.ToDouble(Console.ReadLine()); 
            double newBal = myBal + newDepo; 
            return (newBal);
        }

        static double Withdraw(double myBal) 
        {
            Console.WriteLine("How much would you like to withdraw?");  
            double newDepo = Convert.ToDouble(Console.ReadLine());  
            double newBal = myBal - newDepo; 

            return (newBal);
        }
       
        public class BankMenu
        {
            static void Main(string[] args)
            {
                double myBalance = 466.55; 
                int MenuOpt = 0; 
                string customerName = "User  #21"; 
                string accountNumber = "123456"; 
                double OverDraft = 50.00; 

                //Console Options    

                do
                {
                    Console.WriteLine("Hello, " + customerName + "Account number: " + accountNumber);
                    Console.WriteLine("1. View Balance");
                    Console.WriteLine("2. Make a Deposit");
                    Console.WriteLine("3. Withdraw Money");
                    Console.WriteLine("4. View Overdraft");
                    Console.WriteLine("5. Exit Program");

                    //Menu function here

                    MenuOpt = Convert.ToInt32(Console.ReadLine());

                    if (MenuOpt == 1)
                    {
                        DisplayBankBal(myBalance);
                    }
                    else if (MenuOpt == 2)
                    {
                        double newBal = Deposit(myBalance);
                        Console.WriteLine("Your new balance is " + newBal);
                        myBalance = newBal;
                    }
                    else if (MenuOpt == 3)
                    {
                        double newBal = Withdraw(myBalance);
                        Console.WriteLine("Your new balance is " + newBal);
                        myBalance = newBal;
                    }
                    else if (MenuOpt == 4)
                    {
                        Console.WriteLine("Your remaining overdraft is " + OverDraft);

                    }
                    else Console.WriteLine("Invalid Option");
                } while (MenuOpt != 5);

                //   Console.WriteLine("Your new balance is £" + newBal); //Return new
                Console.WriteLine("
Press any key to continue");
                Console.ReadKey();

            }
        }
    }
}
question from:https://stackoverflow.com/questions/65649175/c-sharp-overdraft-addition

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...