Dice challenge from the video[help]

Updated on October 30, 2017 in [A] Brackeys Courses
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on October 29, 2017

I’m just new into programming and I want to make the dice app challenge but using for loop instead of while
it works almost fine but when it gets 6 it counts the attempt but doesn’t show the 6 can I do something about it

Here is my code :

        static void Main(string[] args)
        {
            Random nrgen = new Random();
            int nrofattempts = 1;
            int attempt = 0;
            for (attempt = 0; attempt != 6; attempt = nrgen.Next(1, 7))
            {
                Console.WriteLine(“Attempt hit  ” + attempt);
                nrofattempts++;
            }
            Console.WriteLine(“It took  ” + nrofattempts + ” attempts to hit 6″);
            Console.ReadKey();
        }
and here is image if you don’t understand what I mean 

https://imgur.com/a/LNsM7

  • Liked by
Reply
1 on October 29, 2017

I hadn’t much time to look into this, as i was in the middle of writing an assessment and thought i’d pop on, I can offer you a quick solution until i can look further into it: 

 

  static void Main(string[] args)
        {
            Random nrgen = new Random();
            int nrofattempts = 1;
            int attempt = 0;
            for (attempt = 0; attempt != 6; attempt = nrgen.Next(1, 7))
            {

 

                Console.WriteLine(“Attempt hit  ” + attempt);
                nrofattempts++;
            }
           if(attempt == 6)
          {
           Console.WriteLine(“Attempt hit ” + attempt);
          }
            Console.WriteLine(“It took  ” + nrofattempts + ” attempts to hit 6″);
            Console.ReadKey();
        }
on October 30, 2017

ah yes I forgot I could make it another specific task if it hits 6 , thank you 

Show more replies
  • Liked by
Reply
Cancel