View Single Post
Old Feb 17th, 2006, 1:50 PM   #5
absentmindedjwc
Newbie
 
Join Date: Feb 2006
Location: Near Chicago
Posts: 5
Rep Power: 0 absentmindedjwc is on a distinguished road
ok, I fixed the inf loop, but now I have come across a logic error..... somewhere in here, lol

I think I said I am trying to make a ATM program, where a user punches in his number and pin (works), and then makes a decision wheather to Withdraw from his account, deposit, or get a balance.... there is the problem... it is saying that the balance is zero, but in the array at the top, it is stated that it is 900 (or 1000, i forgot, lol)

if you have any ideas, please let me know, here is the code:

using System;

public class ATM
{
	public static void Main()
	{
		int x = 0;
		AccountData[] TransArray = new AccountData[2];
		TransArray[0] = new AccountData();
		TransArray[1] = new AccountData();
		TransArray[0].SetAcctNum(123);
		TransArray[0].SetPinsNum(90);
		TransArray[0].SetAvailableBalance(1000);
		TransArray[1].SetAcctNum(234);
		TransArray[1].SetPinsNum(23);
		TransArray[1].SetAvailableBalance(900);

		string pinString,
			accountString; 
		double pin,
			account;
		Console.Write("Please enter your account number: ");
		accountString = Console.ReadLine();
		account = Convert.ToDouble(accountString);
		Console.Write("Please enter your pin number: ");
		pinString = Console.ReadLine();
		pin = Convert.ToDouble(pinString);
		Console.WriteLine("----------------------------------------------------------");
		Console.WriteLine();

		for(x = 0; x < TransArray.Length - 1; ++x)
		{
			if (TransArray[x].GetAcctNum() == account && TransArray[x].GetPinsNum() == pin)
			{
				Console.Write("Do you want to make a transaction? Y or N...");
			}
			else 
				Console.WriteLine("Invalid account and pin please try again or cancel");

		}
		char response;
		response = GetChar();
		while( response == 'Y' || response == 'y')
		{
			Console.WriteLine("Please select a transaction. Balance (a) or Withdrawal (b) or Deposit (c)");
			response = GetChar();
			switch (response)
			{
				case 'A':
				case 'a':
					BalanceMethod(TransArray[x].GetAvailableBalance());
					break;
				case 'B': 
				case 'b':
					WithdrawalMethod(TransArray[x].GetAvailableBalance());
					break;
				case 'C': 
				case 'c':
					DepositMethod(TransArray[x].GetAvailableBalance());
					break;
				case 'D':
				case 'd':
					CancelMethod();
					break;
				default:
					Console.WriteLine("Invaild Selection");
					break;
			}
		}
	}
	public static char GetChar()
	{
		char answer;
		answer = Convert.ToChar(Console.ReadLine());
		return answer;
	}
	public static void BalanceMethod(double bal)
	{
		Console.WriteLine("Your balance is {0}", bal);
		//return BalanceMethod(double);

	}
	public static void WithdrawalMethod(double bal1)
	{

		double withdrawalAmount;
		double amountWithDrawal;
		Console.WriteLine("Please enter the amount you would like to withdraw?");
		withdrawalAmount = Convert.ToDouble(Console.ReadLine());
		amountWithDrawal = bal1 - withdrawalAmount;
		Console.WriteLine("Your balance after your withdrawal is {0}", amountWithDrawal);
		//return WithdrawalMethod(double);
	}
	public static void DepositMethod(double bal2)
	{
		double depositAmount,
			depositTotal;
		Console.WriteLine("Please enter the amount you would like to deposit.");
		depositAmount = Convert.ToDouble(Console.ReadLine());
		depositTotal = depositAmount + bal2;
		Console.WriteLine("Your balance after the deposit is {0}", depositAmount);
		//return DepositMethod(double);
	}
	public static double CancelMethod()
	{
		Console.WriteLine("Thank you and come again");
		return CancelMethod();
	}

}

class AccountData
{
	private double pinNum,
		acctNum,
		AvailableBalance = 0;

	public double GetPinsNum()
	{
		return pinNum;
	}
	public void SetPinsNum(double pin)
	{
		pinNum = pin;
	}
	public double GetAcctNum()
	{
		return acctNum;
	}
	public void SetAcctNum(double account)
	{
		acctNum = account;
	}
	public double GetAvailableBalance()
	{
		return AvailableBalance;
	}
	public void SetAvailableBalance(double AvailableBalance)
	{
		AvailableBalance = AvailableBalance;
	}
}
absentmindedjwc is offline   Reply With Quote