C
C#3y ago
Catto

I input 40, and yet nothing is written, even tho its above 36?

int UserShiftInputInt;
while (!int.TryParse(Console.ReadLine(), out UserShiftInputInt) && UserShiftInputInt > 0 && UserShiftInputInt <= 36)
{
Console.WriteLine("Please only input whole positive numbers between 1 and 36." + Environment.NewLine);
};
int UserShiftInputInt;
while (!int.TryParse(Console.ReadLine(), out UserShiftInputInt) && UserShiftInputInt > 0 && UserShiftInputInt <= 36)
{
Console.WriteLine("Please only input whole positive numbers between 1 and 36." + Environment.NewLine);
};
9 Replies
canton7
canton73y ago
That looks a bit confused. "While the input is not an int, and it's > 0 and it's <= 36, tell the user to input a number between 1 and 36" If the input is not an int, how can it be >0 and <= 36? And ignoring that, if it's >0 and <= 36, why tell them the number should be between 1 and 36?
Catto
CattoOP3y ago
Ah, but if its not an int why does it go check the other condition? why does it bother mhmm
canton7
canton73y ago
Because that's what the code you wrote tells it to do...?
Catto
CattoOP3y ago
yea but if it didnt meet the first condition then it doesnt matter if it meets the other ones right
canton7
canton73y ago
I suspect you meant "While the input is not an int OR it's LESS than 0 OR it's MORE than 36, tell them to input a number between 1 and 36"
Catto
CattoOP3y ago
also yea my bad, i meant to do that btw even if i try 30 tho i tried 30 and it sitll didnt give any errors even with that code as is right now
canton7
canton73y ago
Well yes, it only prints a message if the number is not an int and 30 is an int
Catto
CattoOP3y ago
Ohhhhhhhhhhhhh my bad i overlooked that damnnn thanks
canton7
canton73y ago
No worries!

Did you find this page helpful?