d3adin.
d3adin.
CC#
Created by d3adin. on 12/29/2023 in #help
✅ Console Readline accepting empty value.
Hi all, I'm trying to set console readline to not accept empty value (""). However, I've tried a bunch of different options and I still get "System.FormatException: 'The input string '' was not in a correct format.' " Here is my code
do
{
Console.WriteLine("Player 1, how far away from the city do you want to station the Manticore? ");
manticoreDistance = Convert.ToInt32(readResult);
} while (manticoreDistance < 0 || manticoreDistance > 100);
Console.Clear();
do
{
Console.WriteLine("Player 1, how far away from the city do you want to station the Manticore? ");
manticoreDistance = Convert.ToInt32(readResult);
} while (manticoreDistance < 0 || manticoreDistance > 100);
Console.Clear();
Ideally the goal was to make a loop that displays a message stating that a number needs to be entered.
10 replies
CC#
Created by d3adin. on 11/5/2023 in #help
❔ Console.ReadLine != null
Hi all, I'm went trough this Microsoft challenge (unsuccessfully) and after reviewing this solution I'm trying to understand what the purpose is of:
if (readResult != null)
{
valueEntered = readResult;
}
if (readResult != null)
{
valueEntered = readResult;
}
Upon testing I can see that the code works exactly the same that being commented out. Here is the full program.
string? readResult;
string valueEntered = "";
int numValue = 0;
bool validNumber = false;

Console.WriteLine("Enter an integer value between 5 and 10");

do
{
readResult = Console.ReadLine();
if (readResult != null)
{
valueEntered = readResult;
}

validNumber = int.TryParse(valueEntered, out numValue);

if (validNumber == true)
{
if (numValue <= 5 || numValue >= 10)
{
validNumber = false;
Console.WriteLine($"You entered {numValue}. Please enter a number between 5 and 10.");
}
}
else
{
Console.WriteLine("Sorry, you entered an invalid number, please try again");
}
} while (validNumber == false);

Console.WriteLine($"Your input value ({numValue}) has been accepted.");

readResult = Console.ReadLine();
string? readResult;
string valueEntered = "";
int numValue = 0;
bool validNumber = false;

Console.WriteLine("Enter an integer value between 5 and 10");

do
{
readResult = Console.ReadLine();
if (readResult != null)
{
valueEntered = readResult;
}

validNumber = int.TryParse(valueEntered, out numValue);

if (validNumber == true)
{
if (numValue <= 5 || numValue >= 10)
{
validNumber = false;
Console.WriteLine($"You entered {numValue}. Please enter a number between 5 and 10.");
}
}
else
{
Console.WriteLine("Sorry, you entered an invalid number, please try again");
}
} while (validNumber == false);

Console.WriteLine($"Your input value ({numValue}) has been accepted.");

readResult = Console.ReadLine();
13 replies
CC#
Created by d3adin. on 11/2/2023 in #help
❔ Microsoft learn challenges
Is it normal to really struggle with the MS C# challenges? I've spent more than 7-8 hours all together to figure challenges in this section https://learn.microsoft.com/en-us/training/modules/csharp-do-while/ and I still managed to fail. Even with the research.
11 replies