I have the following code:
int orderQuantity;
Write("Number of Items: \t");
while(int.TryParse(ReadLine(), out orderQuantity) && orderQuantity > 0 == false)
{
Write("Error: Number of Items must be a positive, whole number: \t");
int.TryParse(ReadLine(), out orderQuantity);
}
The goal is that while the input is not a positive integer, continue to return an error. Once the input is a positive integer, continue on.
The problem is this logic only works with the negative numbers. When I try to make the code into while(!int.TryParse(ReadLine(), out orderQuantity) && orderQuantity > 0 == false)
I run into the code not recognizing integers nor negative numbers as errors.
while (!int.TryParse(ReadLine(), out orderQuantity) || orderQuantity <= 0)- "While the line couldn't be parsed as an int OR the parsed value was less than or equal to zero". And remove the parse inside the loop - it's being done in thewhilestatement.