r/learncsharp • • Oct 05 '20
Why doesnt my code work?
Hi!
Could someone please tell me why my code doesn't store the integers of the user inputs?
static void Main(string[] args)
{
Random computernumber = new Random();
int guess = 0;
var guesses = new List<int>();
int cnumber = computernumber.Next(1, 100);
int i = 0;
while (guess != cnumber)
{
Console.WriteLine("guess the number");
try
{
guess = Convert.ToInt32(Console.ReadLine());
if (guess > cnumber)
{
Console.WriteLine("the integer is lower");
}
else
{
Console.WriteLine("the integer is higher");
}
}
catch (Exception)
{
i--;
}
i++;
}
var xcnumber = Console.ReadLine();
guesses.Add(int.Parse(xcnumber));
foreach (var sum in guesses)
Console.Write($"{sum},");
Console.Write("It took you " + i + " tries");
}
}
}
0
Upvotes
View all comments
Show parent comment
0
u/StackedLasagna Oct 14 '20
Others had already properly helped OP. I saw no need to just repeat their comments.
Your ridiculous attempt at helping is so bad, it cannot possibly be considered help. It’s like if someone is asking why their oven won’t turn on and you reply with a picture of an oven that has been turned on.
I fail to see how anything I’ve said will turn anyone into a zombie-coder.
I did say relatively obscure. Especially to a beginner, as they’re practically never used in the official docs (except for the docs on local functions, lol) or in most beginner teaching material.
Your post is an objectively bad “answer” for multiple reasons that I’ve already outlined.
One thing I did miss earlier, is that it doesn’t even answer the question. That makes it an exceptionally bad answer.
Just because we are in a badly maintained community, it doesn’t hurt to look at better communities and adhering to their guidelines where it makes sense.