# Problem 4

The statement reads:

> Write a program that asks the user to guess your favorite number, and ask as long as the user did not guessed it or entered a value that was not an integer. You should keep the count of the “valid” attempts, i.e., of the number of times the user entered an integer that was not your favorite number.

A possible solution is:

        const int FAVORITE = 11;
        int guess;
        int count = 0;
        do{
            Console.WriteLine ("Try to guess my favorite number!");
            if (int.TryParse(Console.ReadLine(), out guess)){count++;}
        }while(guess != FAVORITE);
        Console.WriteLine($"You won, my number was {FAVORITE}! It took you {count} attempts!");

If your favorite number is 0, then the program has to be adapted. Can you see why?

# Problem 5

The statement reads:

> Write a program that uses a while loop to simulate the throwing of a 6-sided dice 20 times, displaying the outcome of every throw, and then display at the screen the total number that was obtained.

A possible solution is:

            Random r = new Random();
            int i = 0, count = 0, res;
            while (i < 20){
                res = r.Next(6) + 1;
                Console.Write($"Throw {i+1}: {res}  ");
                count += res;
                i++;
            }
            Console.WriteLine($"\nTotal: {count}.");