C#
- count =0;
- Create a 2d array \"items\".
string[,] items = new string[100, 4];
- Create a do while loop, when the user enters \"0\", stop theloop.
- Users enter the item name, price, quantity, save this info andsubtotal to array.
- increase \"count++\"
-convert price(decimal, Convert.ToDecimal() ) and quantity(int)to do multiplication
for subtotal
- create a for loop (with count ) to cycle through the \"items\",display item name, price, quantity,
and subtotal.
accumulate subtotal
- Display total items, subtotal, total at the end.
Guide:
string[,] items = new string[100, 4];
int i, j, count;
/* input each array element's value */
for (i = 0; i < 100; i++) {
items[i,0] = Console.ReadLine(\"Enter Item Name: \");
if items[i,0] == \"0\"
break;
else
count++;
items[i,1] = Console.ReadLine(\"Enter Item Price: \");
items[i,2] = Console.ReadLine(\"Enter Item Quantity: \");
items[i,3] =(Convert.ToDouble(items[i,1])*Convert.ToDouble(items[i,2])).toString();
}
/* output each array element's value */
for (i = 0; i < count; i++)
{
for (j = 0; j < 4; j++) {
Console.WriteLine(items[i,j], \" \");
}
}