I need to list a bunch of strings from a loop but have no idea how to

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Alright, so i made a list of items and prices for each item and i wanted to find a way to make it so that i could make as many purchases i want. i also got it so that i could name the total price of all the items, but what i need help with is listing all the items listed in the loop. i have a feeling i might have to use an array, but im pretty new at this so i have no idea how to use one properly.

int i, numitems;
string items;
double price, totalprice;

totalprice = 0;

Console.WriteLine("You are shopping at a food shop and this is the menu");
Console.WriteLine("Breakfast");
Console.WriteLine(" ____________________ ");
Console.WriteLine("| Price | Items |");
Console.WriteLine("|--------|-----------|");
Console.WriteLine("| $0.99 | Coffee |");
Console.WriteLine("| $0.99 | Tea |");
Console.WriteLine("| $0.99 | Juice |");
Console.WriteLine("| $2.99 | Bagel |");
Console.WriteLine("| $2.99 | Pancakes |");
Console.WriteLine(" ____________________ ");
Console.WriteLine("Lunch");
Console.WriteLine(" ____________________ ");
Console.WriteLine("| Price | Items |");
Console.WriteLine("|--------|-----------|");
Console.WriteLine("| $0.99 | Soda |");
Console.WriteLine("| $0.99 | Tea |");
Console.WriteLine("| $0.99 | Juice |");
Console.WriteLine("| $3.99 | Sandwich |");
Console.WriteLine("| $2.99 | Falafel |");
Console.WriteLine(" ____________________ ");
Console.WriteLine("Dinner");
Console.WriteLine(" ____________________ ");
Console.WriteLine("| Price | Items |");
Console.WriteLine("|--------|-----------|");
Console.WriteLine("| $9.99 | Whine |");
Console.WriteLine("| $0.99 | Juice |");
Console.WriteLine("| $0.99 | Soda |");
Console.WriteLine("| $4.99 | Soup |");
Console.WriteLine("| $6.99 | Steak |");
Console.WriteLine(" ____________________ ");

Console.Write("How many purchases would you like to make?: ");
numitems = Convert.ToInt16(Console.ReadLine());

for (i = 1; i <= numitems; i++)
{
Console.Write("Enter in the name of the item you are purchasing: ");
items = Convert.ToString(Console.ReadLine());
Console.Write("Enter in the price of the item you are purchasing (dont include the dollar sign): ");
price = Convert.ToDouble(Console.ReadLine());

totalprice = totalprice + price;
}

Console.WriteLine("The total price of your items are $" + totalprice);

//and this is where i need help
Console.WriteLine("The items that you have purchased are: ");



Console.ReadLine();

View the full article
 
Back
Top