Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:55:54+00:00 2026-06-15T23:55:54+00:00

I am new to c# and coding in general. To try and improve my

  • 0

I am new to c# and coding in general. To try and improve my skills I am trying to create a basic game where two players roll a dice and keep record of their score. The player wins by reaching 20. Each player takes turns rolling a dice adding their first roll to their second and so on until one of them reaches 20. A player can roll the dice again if they roll a six.

The current code I have is:


        do
        {

            Console.Write("Enter the name of Player 1: ");
            Player[0] = Console.ReadLine();
            Console.Write("Enter the name of Player 2: ");
            Player[1] = Console.ReadLine();

            Random DiceRandom = new Random();
            DiceThrow[0] = DiceRandom.Next(1, 7);

            int i = 0;
            while (i <= 1)
            {
                DiceThrow[0 + i] = DiceRandom.Next(1, 7);
                Console.ReadLine();
                Console.Write(Player[0 + i] + " rolled a " + DiceThrow[0 + i]);
                if (DiceThrow[0 + i] != 6) i++;
            }

            Console.ReadLine();
            PlayerTotal[0] = DiceThrow[0];
            PlayerTotal[1] = DiceThrow[1];


            Console.ReadLine();
            Console.Write(Player[0] + " currently has " + PlayerTotal[0]);
            Console.ReadLine();
            Console.Write(Player[1] + " currently has " + PlayerTotal[1]);
            Console.ReadLine();

        }
        while (PlayerTotal[0] == 20);
        while (PlayerTotal[1] == 20);

What I am specifically struggling with is adding the players first roll to there second roll. And if a player rolls a six that it adds the 6 to what they get in the re-roll.

Any help at all will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:55:55+00:00Added an answer on June 15, 2026 at 11:55 pm

    There are a number of concerns with your code here:

    1. you are asking the player name inside the loop
    2. You are initializing the Random generator inside the loop (this can cause same results on different loops because the random generator can use the same seed)
    3. You are resetting totals using = instead of +=
    4. The stop condition is totals == 20 instead of total < 20
    5. you are using two while statement instead of an AND (&&) condition

    This is just a brief overview..

    This can be a solution:

      Console.Write("Enter the name of Player 1: ");
      Player[0] = Console.ReadLine();
      Console.Write("Enter the name of Player 2: ");
      Player[1] = Console.ReadLine();
    
      Random DiceRandom = new Random();
    
      do
        {
    
            int i = 0;
            while (i <= 1)
            {
                int thisThrow = DiceRandom.Next(1, 6);
                DiceThrow[0 + i] += thisThrow;
                Console.ReadLine();
                Console.Write(Player[0 + i] + " rolled a " + thisThrow);
                if (thisThrow != 6) i++;
            }
    
            Console.ReadLine();
            PlayerTotal[0] += DiceThrow[0];
            PlayerTotal[1] += DiceThrow[1];
    
    
            Console.ReadLine();
            Console.Write(Player[0] + " currently has " + PlayerTotal[0]);
            Console.ReadLine();
            Console.Write(Player[1] + " currently has " + PlayerTotal[1]);
            Console.ReadLine();
    
        }
        while (PlayerTotal[0] < 20 && PlayerTotal[1] < 20);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to coding - I can do some basic HTML. I'm trying
I am new to python and coding in general. I am trying to read
Am relatively new to C# and coding in general. I am trying to write
I am new to Stack OverFlow and coding in general. I am trying to
I am new to python (well to coding in general) and am trying to
I'm fairly new to coding in general, learning to code in rails, and feel
I'm new to facebook development and coding in general. I know there are currently
I'm very new to OOP and am trying my hardest to keep things strictly
I am new to python and coding in general and I need help with
I'm very new to coding in general, so I apologize ahead of time if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.