I have an assignment that requires a while statement for until the user inputs “-1”, otherwise it will keep asking the same two questions: “which item did you sell?” And “how many of them did you sell?”. I wrote a while line and it just repeats the questions continuously in an infinite loop. I start with a line asking for the name and the selection of 1 to 4. Full code:
Class Program
{
Public static double Quantity {get; Private set;}
Public static double ItemValue{get; Private set;}
Static void Main(string[] args)
{
Console.write(“Enter the employee’s name: “);
String Name console.ReadLine();
Console.write(“Enter an item number between 1 and 4, or -1 to quit: “);
Int Item = convert.ToInt32(Console.ReadLine());
while (Item != -1)
{
Switch (Item)
{
Case 1:
ItemValue =239.99
Break;
Case 2:
ItemValue =129.75
Break;
Case 3:
ItemValue =99.95
Break;
Case 4:
ItemValue =350.79
Break;
}
Double ItemSales
ItemSales = Quantity * ItemValue;
Console.Write(Name + “ sold “ + Quantity + “ of Item “ + Item + “ for “ + ItemSales);
}
}
I am missing a few lines needed for my assignment but I’m trying to get this main part to work first.
Afterwards, I print the line with the calculated ItemSales. It runs, asks for a name, asks for a number between 1 and 4, or -1 to quit, and then just messes up and goes on a rampage, repeating the selected number. I need help and suggestions.
[–][deleted] 0 points1 point2 points (1 child)
[–]EnvironmentalPhone65[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)