Can't figure out how to have the while loop running continuously for each input. Thanks for any help :)
Not sure if while (true) is needed or not, I'm still new to all of this :D
private static void AddToStock()
{
//Confirm item id is greater than 0
int itemid = ReadInteger("\nItem ID:");
string itemname = ReadString("Item Name:");
int itemquantity = ReadInteger("Quantity:");
double itemprice = ReadDouble("Price Paid:");
DateTime itemdate = ReadDate("Date Added:");
while (true)
{
if (itemid <= 0)
{
Console.WriteLine("Item ID Cannot Be Less Than 1, Please Try Again");
itemid = ReadInteger("Item ID:");
break;
}
//Confirm item quantity is greater than 0
if (itemquantity <= 0)
{
Console.WriteLine("Quantity Cannot Be Less Than 1, Please Try Again");
itemquantity = ReadInteger("Quantity:");
break;
}
//Confirm item price is greater than 0.01
if (itemprice < 0.01)
{
Console.WriteLine("Item Price Cannot Be Less Than 0, Please Try Again");
itemprice = ReadDouble("Item Price:");
break;
}
}
//Add item to stock
Employee_UI.AddToStock(itemid, itemname, itemprice, itemquantity, itemdate);
Console.WriteLine("\nItem Added To Stock!");
}
itemquantity. As you step through in the debugger, explaining to the rubber duck, you find that the code detects the problem and prompts the user to enter a correct value. Then it does an odd thing: it does abreakinstead ofcontinueand doesn't validate the new input or subsequent parameters. You and the rubber duck look at each other and ... .