I have an array in class array and I'd like to access it's members in class table. I'm lost on how to do this. Any help would be greatly appreciated, thanks.

using System;

public class Restaurant
{
    //Writes a welcome message.
    public void Welcome()
    {//start Welcome method

        Console.WriteLine("Welcome to Qdoba!\n");

    }//end Welcome method

    public class array //can't access these in the table class
    {
                    int[][] table = new int[8][];
            table[0] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            table[1] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[2] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[3] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[4] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[5] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[6] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[7] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
    }

    public class Table
    {
        public void tables()
        {
            Items item = new Items();
            Menu menu = new Menu();


            int orderMore = 0;
            do
            {
                Console.WriteLine("What is your table number? (1-7)");
                int tables = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine();
                if (tables == 1)
                {
                    menu.menu();
                    Console.WriteLine("What would you like to order?");
                    int order = Convert.ToInt32(Console.ReadLine());
                    ++table[1][order];
                    Console.WriteLine(table[1][order]);
                    Console.WriteLine("Would you like to order anything else?  Type '1' to order more, '0' to stop.");
                    orderMore = Convert.ToInt32(Console.ReadLine());
                }

                if (tables == 2)
                {
                    Console.WriteLine("What would you like to order?");
                    int order = Convert.ToInt32(Console.ReadLine());
                    ++table[2][order];
                    Console.WriteLine(table[2][order]);
                    Console.WriteLine("Would you like to order anything else?  Type '1' to order more, '0' to stop.");
                    orderMore = Convert.ToInt32(Console.ReadLine());
                }


            }
            while (orderMore != 0);



            


        }       

    }

    public class Menu
    {
        public void menu()
        {
            Items i = new Items();
            double[] price  = { i.ChipsPrice, i.QuesoPrice, i.GuacamolePrice, i.ChickenBurritoPrice, i.SteakBurritoPrice,
                               i.PestoBurritoPrice, i.PorkBurritoPrice, i.QuesadillaPrice, i.SodaPrice, i.TeaPrice, i.SnapplePrice};
            string[] items  = { "Chips\t\t", "Queso\t\t", "Guacamole\t\t", "Chicken Burrito\t", "Steak Burrito\t", "Pesto Burrito\t",
                               "Pork Burrito\t\t", "Quesadilla\t\t", "Soda\t\t\t", "Tea\t\t\t", "Snapple\t\t"};

            int[] number    = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

            for (int j = 0; j < number.Length; j++)
            {//start for

                Console.WriteLine("{0}) {1} {2:C}", number[j], items[j], price[j]);

            }//end for
            Console.WriteLine();
        }
    }

    public class Items
    {
        //appetizers
        public int Chips = 77;
        public double ChipsPrice = 1.99;
        public int Queso = 0;
        public double QuesoPrice = 2.49;
        public int Guacamole = 0;
        public double GuacamolePrice = 2.99;

        //entrees
        public int ChickenBurrito = 0;
        public double ChickenBurritoPrice = 5.99;
        public int SteakBurrito = 0;
        public double SteakBurritoPrice = 6.49;
        public int PestoBurrito = 0;
        public double PestoBurritoPrice = 5.99;
        public int PorkBurrito = 0;
        public double PorkBurritoPrice = 6.49;
        public int Quesadilla = 0;
        public double QuesadillaPrice = 4.99;

        //drinks
        public int Soda = 0;
        public double SodaPrice = .99;
        public int Tea = 0;
        public double TeaPrice = 1.19;
        public int Snapple = 0;
        public double SnapplePrice = 1.49;

    }

    public class Order
    {
        public void order()
        {
            Console.WriteLine("To start a new tab type 1.  To add to a tab type 2.  To close a tab type 3.");

            string tab = Console.ReadLine();
            Console.WriteLine();

            Table t = new Table();

            //start a new tab
            if (tab == "1")
            {//start if
                                
                t.tables();
                Console.WriteLine();
                order();

            }//end if

            if (tab == "2")
            {//start if

                
                t.tables();
                Console.WriteLine();
                Console.WriteLine("\nIs the table ready for the check?  If yes, type 1.  If no, type 2.");
                string addTab = Console.ReadLine();
                if (addTab == "1")
                {//start if

                    tab = "0";
                   // Bill();

                }//end if

                if (addTab == "2")
                {//start if

                    tab = "0";
                    order();

                }//end if

            }//end if
        }
 
    }
    

}

public class Driver : Restaurant
{
    public static void Main()
    {


        Restaurant r = new Restaurant();
        r.Welcome();
        Order o = new Order();
        o.order();

        
    }
}

Your array table is private!!!

I think I don't understand you, can you please explain more!

What I'm trying to do is have the array hold the table number and also hold the amount of items ordered. I'd like to have it in it's own class. I've been having trouble with it resetting to default values (0) - that's why I want it in it's own class.

The code below works, but when you go to add to a tab all the array values for that table get reset to their default value.

Hope this is easier to understand. Thanks.

using System;

public class Restaurant
{
    //Writes a welcome message.
    public void Welcome()
    {//start Welcome method

        Console.WriteLine("Welcome to Qdoba!\n");

    }//end Welcome method

    public class Table
    {
        public void tables()
        {
            Items item = new Items();
            Menu menu = new Menu();
            int[][] table = new int[8][];
            table[0] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            table[1] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[2] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[3] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[4] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[5] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[6] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };
            table[7] = new int[] { 0, item.Chips, item.Queso, item.Guacamole };

            int orderMore = 0;
            do
            {
                Console.WriteLine("What is your table number? (1-7)");
                int tables = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine();
                if (tables == 1)
                {
                    menu.menu();
                    Console.WriteLine("What would you like to order?");
                    int order = Convert.ToInt32(Console.ReadLine());
                    ++table[1][order];
                    Console.WriteLine(table[1][order]);
                    Console.WriteLine("Would you like to order anything else?  Type '1' to order more, '0' to stop.");
                    orderMore = Convert.ToInt32(Console.ReadLine());
                }

                if (tables == 2)
                {
                    Console.WriteLine("What would you like to order?");
                    int order = Convert.ToInt32(Console.ReadLine());
                    ++table[2][order];
                    Console.WriteLine(table[2][order]);
                    Console.WriteLine("Would you like to order anything else?  Type '1' to order more, '0' to stop.");
                    orderMore = Convert.ToInt32(Console.ReadLine());
                }


            }
            while (orderMore != 0);



            


        }       

    }

    public class Menu
    {
        public void menu()
        {
            Items i = new Items();
            double[] price  = { i.ChipsPrice, i.QuesoPrice, i.GuacamolePrice, i.ChickenBurritoPrice, i.SteakBurritoPrice,
                               i.PestoBurritoPrice, i.PorkBurritoPrice, i.QuesadillaPrice, i.SodaPrice, i.TeaPrice, i.SnapplePrice};
            string[] items  = { "Chips\t\t", "Queso\t\t", "Guacamole\t\t", "Chicken Burrito\t", "Steak Burrito\t", "Pesto Burrito\t",
                               "Pork Burrito\t\t", "Quesadilla\t\t", "Soda\t\t\t", "Tea\t\t\t", "Snapple\t\t"};

            int[] number    = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

            for (int j = 0; j < number.Length; j++)
            {//start for

                Console.WriteLine("{0}) {1} {2:C}", number[j], items[j], price[j]);

            }//end for
            Console.WriteLine();
        }
    }

    public class Items
    {
        //appetizers
        public int Chips = 77;
        public double ChipsPrice = 1.99;
        public int Queso = 0;
        public double QuesoPrice = 2.49;
        public int Guacamole = 0;
        public double GuacamolePrice = 2.99;

        //entrees
        public int ChickenBurrito = 0;
        public double ChickenBurritoPrice = 5.99;
        public int SteakBurrito = 0;
        public double SteakBurritoPrice = 6.49;
        public int PestoBurrito = 0;
        public double PestoBurritoPrice = 5.99;
        public int PorkBurrito = 0;
        public double PorkBurritoPrice = 6.49;
        public int Quesadilla = 0;
        public double QuesadillaPrice = 4.99;

        //drinks
        public int Soda = 0;
        public double SodaPrice = .99;
        public int Tea = 0;
        public double TeaPrice = 1.19;
        public int Snapple = 0;
        public double SnapplePrice = 1.49;

    }

    public class Order
    {
        public void order()
        {
            Console.WriteLine("To start a new tab type 1.  To add to a tab type 2.  To close a tab type 3.");

            string tab = Console.ReadLine();
            Console.WriteLine();

            Table t = new Table();

            //start a new tab
            if (tab == "1")
            {//start if
                                
                t.tables();
                Console.WriteLine();
                order();

            }//end if

            if (tab == "2")
            {//start if

                
                t.tables();
                Console.WriteLine();
                Console.WriteLine("\nIs the table ready for the check?  If yes, type 1.  If no, type 2.");
                string addTab = Console.ReadLine();
                if (addTab == "1")
                {//start if

                    tab = "0";
                   // Bill();

                }//end if

                if (addTab == "2")
                {//start if

                    tab = "0";
                    order();

                }//end if

            }//end if
        }
 
    }
    

}

public class Driver : Restaurant
{
    public static void Main()
    {


        Restaurant r = new Restaurant();
        r.Welcome();
        Order o = new Order();
        o.order();

        
    }
}

sorry I can't look at all this code but you want to reset the array?

I just want it so the array doesn't revert back to the default values. When I call the method (where the array is) it goes back to the default values instead of keeping what was entered.

please pay little attention to Ramy! It seems he is just out to have fun!(apologies if i'm wrong).
What you should do is to include some comments to your code. Your code is quite lengthy. Put comments near where you are having the error. Let's take it from there.
NB: Indenting your code might also help.

please pay little attention to Ramy! It seems he is just out to have fun!(apologies if i'm wrong).
what do you mean??!!!

It's actually indented on my machine - running a larger resolution than the forum apparently. Anyways, here is some condensed code with comments:

using System;

public class Restaurant
{   
    //nothing here yet
}

public class Item
{
    //or here
}

public class Table : Item
{
    //to run the below method
    public static void Main()
    {
        Table t = new Table();
        t.Test();
    }

    public void Test()
    {
        int chips = 0;
        int orderMore = 0;
        int tables = 0;
        int order = 0;

        //array
        int[][] table = new int[8][];
        table[0] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
        table[1] = new int[] { 0, 7, 0, 0 };
        table[2] = new int[] { 0, 11, 0, 0 };

        //asks the user their table number, and what they'd like to order, depending on their table number
        do
        {
            Console.WriteLine("What is your table number? (1-7)");
            tables = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            if (table[0][tables] == tables)
            {
                orderMore = 0;

                Console.WriteLine("What would you like to order?");
                order = Convert.ToInt32(Console.ReadLine());
                table[tables][order]++;
                Console.WriteLine("The count is now  " + table[tables][order]);
                Console.WriteLine("Would you like to order anything else?  Type '1' to order more, '0' to stop.");
                orderMore = Convert.ToInt32(Console.ReadLine());
            }

        }
        while (orderMore != 0);

        //this prints out what they've ordered - if table two orders #1 - it'll print out 11 (unless the user ordered more)
        //if table one orders #1 - it'll print our 7 (unless the user ordered more)
        Console.WriteLine("Table 2 amount ordered:  " + table[2][order]);
        Console.WriteLine("Table 1 amount ordered:  " + table[1][order]);

        //runs the below method
        Test p = new Test();
        p.p();


    }

}

public class Test : Table
{
    public void p()
    {

        //this is where I'd like to be able to access the array (ie. be able to output how many table one (in this case) ordered)
        //in this case, how many number one's
        Console.WriteLine("#1:  " + table[1][1]);
    }
}
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.