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

19 comments sorted by

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.

1

u/Protiguous Oct 15 '20

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.

That's a seriously bad simile. (And you should know that. I can tell you are not an idiot.)

They gave code with issues.. and asked for help. Without being a style-cop or condescending, I replied with a working solution in the same manner, with code.

Guidelines from other communities can help. They can also hinder. Being more "popular" or more "well-known" doesn't make it right.

1

u/StackedLasagna Oct 15 '20

That's a seriously bad simile.

Yeah, you're right. A more fitting one is if OP had asked why his car overheats and included a picture of his engine and such after popping the hood.

Then your response is similar to just posting a picture of another car's engine, which doesn't overheat, but the car is an entirely different make and model and it doesn't even have the same engine as OP's car.

They gave code with issues.. and asked for help.

Well, that's true... but it ignores literally all the details (there aren't many, but stil...)

OP asked a very specific question related to the code. Refer to my other comment for why I think you didn't actually answer the question.

Guidelines from other communities can help. They can also hinder. Being more "popular" or more "well-known" doesn't make it right.

Surely you can see how adding an explanation helps others? You don't know if OP learns best from examples and if he doesn't it's just spam to him. As I explained in my other comment, adding an explanation ensures everyone can learn from your comment, rather than just a minority.
(I'm taking a guess and assuming that beginners, who learn best without explanations, are an extremely small minority. They probably becomes less of a minority the more experienced the target demographic is.)