I wanted it to look like this:
And here’s my result:
This is my code
private static void Main(string[] args)
{
Console.WriteLine("CASHIER");
Console.WriteLine("Enter Quantity of Products: ");
int qty = Convert.ToInt32(Console.ReadLine());
if (qty > 5)
{
Console.WriteLine("Maximum of 5 products");
}
else
{
int i = 1;
while (i <= qty)
{
Console.WriteLine(i);
i++;
Console.WriteLine("Enter Price: ");
int price = Convert.ToInt32(Console.ReadLine());
int total = + price;
Console.WriteLine("Total: " + total);
}
}
}
2
Answers
Not sure, that I fully understand your question.
But you should consider declaring your total outside your loop and doing total +=
Your
inside the loop redeclares
total
as a new variable each time your loop executed its block and you always assignprice
in a positive manner to it instead of addingprice
to the previoustotal
. The solution is to:total
outside the loop and initialize it with 0price
to it at each stepIf you want to show
total
only once, at the very end, you need to move your lastConsole.WriteLine
outside (after) the loop.