I'm working on a school assignment. The program is to create a simple restaurant menu and ordering program. The program inputs data from a source file the user selects, displays the menu to them, the user orders, and then the bill is tallied and displayed.
In the main method, I've created an array of objects "menuItems" and have succesfully populated it from an input file. However when I pass the array to the ShowMenu method and use a simple loop to display all the menu options I get 8 lines of blank data. Help please, I'm sure its just something simple that i'm missing but for a beggining programmer its very frustrating.
/*Breakfast Ordering Program
This program will read data from an input file, storing the data in an array,
then it will display ordering options to the customer.
The customer will select the different items they want
as well as the quantities of each item and the program
will then print their order back to the user as well as the total bill. */
class Menu //class from which the object array menuItems will be created.
private string description; //stores the item description.
private double price; //stores the price of the item.
description = "pricea";
price = 0.00;
public string Description
description = value;
public double Price
price = value;
class program //This class houses the program methods and utilizes them in the main method.
static void Main()
/*This method will call the getData method to input data from the input file.
* It will then call the showMenu method to display menu options and allow selections.
* Then it will call the printCheck method which will display the selected menu items and quantities as well as the total bill.
Menu menuItems = new Menu; //stores input data.
int noMenuItems; //stores the number of Menu Items.
int noOrderItems; //stores the number of items ordered.
noMenuItems = GetData(menuItems);
int order = new int[noMenuItems];
// for (int w = 0; w < noMenuItems; w++)
ShowMenu(menuItems, order, noMenuItems);
public static int GetData(Menu menuItems)
//This method imports data from an input file the user specifies and stores it in an array
int i = 0; //loop variable
string fileName; //stored input file name.
string recordIn; //will store input line by line.
string itemString, priceString;
double price; //Used to convert numeric input.
Console.WriteLine("Enter the full filename you wish to import menu from.");
fileName = Console.ReadLine();
if (File.Exists(fileName)) //data validation ensuring proper file name and then imports data
Console.WriteLine("Entry accepted; Input in progress");
FileStream readFile = new FileStream(fileName, FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(readFile);
recordIn = reader.ReadLine();
i = 0;
price = 0;
itemString = ""; //variables initialized
while (recordIn != null) //Loop reads data line by line and storing into the array.
itemString = recordIn;
recordIn = reader.ReadLine();
price = Convert.ToDouble(recordIn);
Menu a = new Menu();
a.Description = itemString;
a.Price = price;
//creates new object with input item and price
menuItems[i] = a; //stores new object in array position i
Please format your code so that it is legible by using code tags.
Your problem is simple; you have an empty array. 'menuItems' is an array of ten 'Menu" objects, but you never actually add anything to it, so it is really just an array with ten empty buckets that are large enough to hold 'Menu' objects.
Out of curiosity, is this 'real' code or an assignment from a programming class? I ask because, if it's for a real project there are many better ways of dealing with a collection than using a raw array.
Edit: nevermind - I see where you mentioned it's a school assignment. (too bad - you don't get to use the generic collection classes <g>)