开发者

c# search array - No overload for method

I keep getting an error when trying to compile my program, i'm having issues with the search part of the code. Not sure what i'm doing wrong.

Here is the error I'm getting when compiling:

week3.cs(97,17): error CS1501: No overload for method 'searchAccounts' takes 1 arguments week3.cs(27,21): (Location of symbol related to previous error)

Here is my entire code:

using System;

class Accounts
    {
        // private class members
        const int arrayLength = 5;
        private int [] Account = new int[arrayLength]; //create arrays
        private double [] AcctBalance = new double[arrayLength];
        private string [] LastName = new string[arrayLength];

        // fill all three parallel arrays with input
        public void fillAccounts(int[] Account, double[] AcctBalance, string[] accountNameArray)
        {
            int arrayLength = 0;
            for (int i = 0; i < Account.Length; i++)
            {
                Console.Write("Enter integer account number ");
                Account[arrayLength] = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter account balance ");
开发者_运维问答                AcctBalance[arrayLength] = Convert.ToDouble(Console.ReadLine());
                Console.Write("Enter account holder last name ");

            } //end for

        } //end fillAccounts method

        public void searchAccounts(int[] Account, double[] AccountBalance, string[] LastName)
        {
            int accountNum = 0;
            bool isValid = false;
            int x = 0;

            Console.Write("Please enter the account number you wish to search for ");
            accountNum = Convert.ToInt32(Console.ReadLine());

            while (x < Account.Length && accountNum != Account[x])
                ++x;
            if(x != Account.Length)
            {
                isValid = true;
            }
            if(isValid)
                Console.WriteLine("Account number " + Account[x] + " has a balance of " + AcctBalance[x]
                    + " and the account holder is " + LastName[x]);
            else
                Console.WriteLine("No such account as {0}", accountNum);


        }

        public void averageAccounts(int[] Account, double[] AcctBalance)
        {
            // compute and display average of all 5 bal as currency use length.
            int balanceCount = 0;
            double balance = AcctBalance[balanceCount];
            double balanceSum = 0;
            double averageBalance = 0;

            for (int i = 0; i < Account.Length; i++)
            {
                balanceSum = balanceSum + balanceCount;
            }
            averageBalance = (balanceSum/balanceCount);
        } //end averageAccounts method
    } //end public class accounts


    class account_assignment  //wrapper class for main
    {
        static void Main()
        {
        int[] Account; 
        double[] AcctBalance; 
        string[] LastName;
            char entry;
            char a, A;
            char b, B;
            char x, X;

            //instantiate one new Accounts object
            Accounts accounts = new Accounts();

            //call class methods to fill accounts Array
            accounts.fillAccounts(Account, AcctBalance, LastName);
            //menu detailing entnries to select search (a or A) average (b or B) exit (x or X)


            Console.WriteLine("*****************************************");
            Console.WriteLine("enter an a or A to search account numbers");
            Console.WriteLine("enter a b or B to average the accounts");
            Console.WriteLine("enter an x or X to exit program");
            Console.WriteLine("*****************************************");

            entry = Convert.ToChar(Console.ReadLine());

            if (entry == 'a' || entry == 'A')
                accounts.searchAccounts(Account);
            if (entry == 'b' || entry == 'B')
                accounts.averageAccounts(Account, AcctBalance);
            if (entry == 'x' || entry == 'X')
                Console.WriteLine("The program will now close");

            //internal documentation
        } //end main
    }

Any help would be greatly appreciated.


The line :

accounts.searchAccounts(Account);

Is calling searchAccounts with one parameter.

whereas searchAccounts has this requirement:

public void searchAccounts(int[] Account, double[] AccountBalance, string[] LastName)


Replace

accounts.searchAccounts(Account);

with

accounts.searchAccounts(Account, AcctBalance, LastName);

As declared right now searchAccounts needs three parameters, not just the one you are trying to pass - the other two are not optional (although you don't seem to use the account balance at all in searchAccounts())

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜