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

class Program
{
 public class AccountInfo 
    { 
        public int Number { get; set; } 
        public double Balance { get; set; } 
        public string LastName { get; set; } } 
    // private class members, creating new arrays 
    private int [] 
        AcctNumber = new int[5]; 
    private double [] 
        AcctBalance = new double[5];
}
    public static void Main() 

    { 
        List<AccountInfo> accounts = new List<AccountInfo>(); 
        for (int index = 1; index < 6; index++) 
        {
            AccountInfo acc = new AccountInfo(); 
            Console.Write("Enter account number: " + index.ToString() + ": "); 
            acc.Number = int.Parse(Console.ReadLine()); 
            Console.Write("Enter the account balance: "); 
            acc.Balance = double.Parse(Console.ReadLine()); 
            
        }
}

class Accounts
{    
public void fillAccounts()//fill arrays with user input     
{        
        int x = 0;        
        for 
        (int i = 0; i < AcctNumber.Length; i++)     
    {            
        Console.Write("Enter account number: ");                         
        AcctNumber[x] = Convert.ToInt32(Console.ReadLine());           
        Console.Write("Enter account balance: ");            
        AcctBalance[x] = Convert.ToDouble(Console.ReadLine());                       
        x++;         
    }       
}     

public void searchAccounts() //search account method to be called later in main()     
{         
        int accountNum = 0;        
        bool isValid = false;         
        int x = 0;          

        Console.Write("Please enter account number to search for: ");         
        accountNum = Convert.ToInt32(Console.ReadLine());           
        while (x < AcctNumber.Length && accountNum != AcctNumber[x])            
        ++x;         
        if(x != AcctNumber.Length)         
    {        
        isValid = true;         
    }             
        if(isValid)
    {         
        Console.WriteLine("AcctNumber: {0} Balance: {1:c}", AcctNumber[x], AcctBalance[x]);         
    }         
        else
    {               
        Console.WriteLine("You entered an invalid account number");          
    }                        
}      

} //end public class Accounts

Getting errors do not know how to fix this. Here is the assignment instructions: Bank currently has only 5 customers.. At this point, each customer has one account, which includes an account number and balance.

1. An Account class that contains private data members; account number and balance.

2. A public class method to get the data.

3. A public class method to search for the a balance by account number.

4. A public class method to output the list of accounts and balances, with appropriate column headers.

5. A main( ) function that instantiates an array of Account objects, and allows user to input an account number and than have the program search for and display the associated balance and then display a list of all 5 balances.

6. Internal Documentation

Recommended Answers

All 5 Replies

Saying you are getting errors does not help us very much.
Wich error and on wich line did it occur?
If you posted your code in code tags we could see some line numbers.

Error Type or namespace definition, or end-of-file expected line 31 column 9
Error does not contain a static 'Main' method suitable for an entry point
Error Expected class, delegate, enum, interface, or struct line 19 column 19
Error Expected class, delegate, enum, interface, or struct line 22 column 42
Error Expected class, delegate, enum, interface, or struct line 25 column 35

Did some rearrangements, errors too much to mention here, although you were on the right way, in a way...
Compare with your code and learn.

class Program
    {
        public static void Main() 
        {
            List<Account> accounts = new List<Account>(); 
            for (int index = 1; index < 6; index++) 
            {
                Account acc = new Account(); 
                Console.Write("Enter account number: " + index.ToString() + ": ");
                acc.Number = int.Parse(Console.ReadLine()); 
                Console.Write("Enter the account balance: "); 
                acc.Balance = double.Parse(Console.ReadLine()); 
            }
        }
    }

    public class Account
    {
        public int Number { get; set; }
        public double Balance { get; set; }
        public string LastName { get; set; }
        // private class members, creating new arrays     
        private int[] AcctNumber = new int[5];
        private double[] AcctBalance = new double[5];

        public void fillAccounts()//fill arrays with user input 
        {
            int x = 0;
            for
            (int i = 0; i < AcctNumber.Length; i++)
            {
                Console.Write("Enter account number: ");
                AcctNumber[x] = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter account balance: ");
                AcctBalance[x] = Convert.ToDouble(Console.ReadLine());
                x++;
            }
        }
    
        public void searchAccounts() //search account method to be called later in main() 
        { 
            int accountNum = 0; 
            bool isValid = false; 
            int x = 0; 

            Console.Write("Please enter account number to search for: "); 
            accountNum = Convert.ToInt32(Console.ReadLine()); 
            while (x < AcctNumber.Length && accountNum != AcctNumber[x]) 
            ++x; 
            if(x != AcctNumber.Length) 
            { 
            isValid = true; 
            } 
            if(isValid)
            { 
            Console.WriteLine("AcctNumber: {0} Balance: {1:c}", AcctNumber[x], AcctBalance[x]); 
            } 
            else
            { 
            Console.WriteLine("You entered an invalid account number"); 
            } 
        } 

    } //end public class Accounts

Okay, so I am totally getting there and thanks I really appreciate your help. Still having an issue. I never get the prompt asking me to enter an account number to search for, which in return is suppose to provide me with the accounts balance. Also, it does not list all the accounts that were inputted along with their balances.

I think you started coding without too much of a plan. :)
Look at lines 9-12 and 32-35 (see my previous post) they are practically the same.

5.A main( ) function that instantiates an array of Account objects, and allows user to input an account number and than have the program search for and display the associated balance and then display a list of all 5 balances.

Tells me to make an array filled with 5 accounts(not input by user, but hard coded)
then user must input account number and the program looks up the balance
you must also be able o show a list of all accounts. Tell me if I'm wrong about that.
So this boils down to some sort of menu you must implement(use a while loop):

1. Input acc nr
2. Show accs
3. Exit program
Success!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.