vendredi 26 juin 2020

Adding value to int variable each run of the loop

sorry if this is a repeat question or sounds pretty stupid, but I'm really new to c# and looked throughout the forum and couldn't find anything that I could actually understand.

So I'm trying to write a simple program where the user tries to guess a number between 1 and 25. Everything works except that each run of the loop instead of updating the score from the last run of the loop, like 0+1=1, 1+1=2, 2+1=3, each time it adds 1 to 0. Here is my code. How do I fix this? Thank you!

int score = 0; int add = 1;

        while (add == 1)
        {
            Console.WriteLine("Guess A Number Between 1 and 25");
            string input = Console.ReadLine();

            if (input == "18")
            {
                Console.WriteLine("You Did It!");
                Console.WriteLine("Not Bad! Your Score was " + score + add);
                break;
            }
            else
            {
                Console.WriteLine("Try Again. Score: " + score + add);
            }
        }

Aucun commentaire:

Enregistrer un commentaire