Note: I am learning to use the arrays.
The issue with my bool method for the parallel array is that I want to return true or false with a message for balance being empty (equal to 0.00 in double data type) or not (return false). I got the result after running this code:
- The balance is not empty False
- The balance is not empty False
- The balance is not empty False
In short, once I run those codes then it will be looping or will not read whether the user's balance is empty or not because it doesn't check if it is zero or less than a zero. Instead, they simply ignore it and then return a false.
Here is my code:
// declaring three parallel arrays that store name, account number, and balance with data types
string [] customerName = new string [2];
int [] bankAccount = new int [2];
double [] balance = new double [2];
customerName = new string [] { "John Doe", "Jane Doe", "John Smith" };
bankAccount = new int [] { 123456 , 654321 , 987654 };
balance = new double [] {100.00, 200.00, 300.00};
for ( int i = 0; i < customerName.Length; i++)
{
Console.WriteLine(customerName[i] + "\t" + "Account Number: " + bankAccount[i] + "\t" + "Balance: $" + balance[i]);
}
// declared three different balances for the deposit method since context is necessary for local variables
double balance1 = balance[0];
double balance2 = balance[1];
double balance3 = balance[2];
Console.WriteLine(isEmpty(balance1));
Console.WriteLine(isEmpty(balance2));
Console.WriteLine(isEmpty(balance3));
bool isEmpty (double balance)
{
bool balance1 = balance == 0;
bool balance2 = balance == 0;
bool balance3 = balance == 0;
if (balance == 0)
{
return true;
}
else
{
Console.WriteLine("The balance is not empty");
}
return balance1 || balance2 || balance3;
}
// hardcoded values for three customers' balances to be updated
double deposit = 200.00;
double deposit1 = 300.00;
double deposit2 = 400.00;
// declared three different customers' names for return with string data type
string firstCustomer = "John Doe";
string secondCustomer = "Jane Doe";
string thirdCustomer = "John Smith";
Console.WriteLine(Deposit(firstCustomer, balance1, deposit));
Console.WriteLine(Deposit(secondCustomer, balance2, deposit1));
Console.WriteLine(Deposit(thirdCustomer, balance3, deposit2));
// string return that will return the three customers with updated balance after the deposit which is string
string Deposit (string customerName, double balance, double deposit)
{
double newBalance = balance + deposit;
return customerName + " deposited $" + deposit + " and the new balance is " + newBalance;
}
Therefore, I need to simply check and then return false or true after deciding if the balance is empty or not. There is no error but simply shows some repeating and ignoring any that is return false. Instead, they will always return true no matter what it is.