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

  • Home
  • SEARCH
  • 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 6193335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:06:07+00:00 2026-05-24T03:06:07+00:00

This is my 2 die roll code namespace Dice_Roll_assignment { public partial class diceRoll

  • 0

This is my 2 die roll code

namespace Dice_Roll_assignment
{
    public partial class diceRoll : Form
    {
        public diceRoll()
        {
            InitializeComponent();
        }

        private void rollDice_Click(object sender, EventArgs e)
        {
            AcceptButton = rollDice;
            if (txtNumRolls.Text.Trim() == "")
            {
                MessageBox.Show("Must enter number of dice rolls");
            }
            else if (txtNumRolls.Text.Trim() == "0")
            {
                MessageBox.Show("Must enter a number greater than 0");
            }
            diceTotal.Text = "Dice Total" + "\n" + 2 + "\n" + 3 + "\n" + 4 + "\n" + 5 + "\n" + 6 + "\n" + 7 + "\n" + 8 + "\n" + 9 + "\n" + 10 + "\n" + 11 + "\n" + 12;
            // This will lead the first label to show the number of dice total

            int numRolls = int.Parse(txtNumRolls.Text);// Converting the textBox value to an integer for randGen
            SimulateRolls(numRolls);           
        }
        private void SimulateRolls(int iNumRolls)
        {
            int numrolls = int.Parse(txtNumRolls.Text);
            Random randGen = new Random();
            // randGen is the new random so we use randGen.Next();
            int oneRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int twoRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int threeRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int fourRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int fiveRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int sixRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int sevenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int eightRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int nineRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int tenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int elevenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int twelveRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int thirteenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int fourteenRoll = randGen.Next(1, 7) + randGen.Next(1, 7);
            int[] arrNumOccurrence = new int[13];
            if (numrolls == 1)
            {
                arrNumOccurrence[oneRoll]++;
            }
            else if (numrolls == 2)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
            }
            else if (numrolls  ==3)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
            }
            else if (numrolls  == 4)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
            }
            else if (numrolls  == 5)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
            }
            else if (numrolls  == 6)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
            }
            else if (numrolls  == 7)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
                arrNumOccurrence[sevenRoll]++;
            }
            else if (numrolls  == 8)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
                arrNumOccurrence[sevenRoll]++;
                arrNumOccurrence[eightRoll]++;
            }
            else if (numrolls  == 9)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
                arrNumOccurrence[sevenRoll]++;
                arrNumOccurrence[eightRoll]++;
                arrNumOccurrence[nineRoll]++;
            }
            else if (numrolls  == 10)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
                arrNumOccurrence[sevenRoll]++;
                arrNumOccurrence[eightRoll]++;
                arrNumOccurrence[nineRoll]++;
                arrNumOccurrence[tenRoll]++;
            }
            else if (numrolls  == 11)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
                arrNumOccurrence[sevenRoll]++;
                arrNumOccurrence[eightRoll]++;
                arrNumOccurrence[nineRoll]++;
                arrNumOccurrence[tenRoll]++;
                arrNumOccurrence[elevenRoll]++;
            }
            else if (numrolls  == 12)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
                arrNumOccurrence[sevenRoll]++;
                arrNumOccurrence[eightRoll]++;
                arrNumOccurrence[nineRoll]++;
                arrNumOccurrence[tenRoll]++;
                arrNumOccurrence[elevenRoll]++;
                arrNumOccurrence[twelveRoll]++;
            }
            else if (numrolls == 13)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
                arrNumOccurrence[sevenRoll]++;
                arrNumOccurrence[eightRoll]++;
                arrNumOccurrence[nineRoll]++;
                arrNumOccurrence[tenRoll]++;
                arrNumOccurrence[elevenRoll]++;
                arrNumOccurrence[twelveRoll]++;
                arrNumOccurrence[thirteenRoll]++;
            }
            else if (numrolls == 14)
            {
                arrNumOccurrence[oneRoll]++;
                arrNumOccurrence[twoRoll]++;
                arrNumOccurrence[threeRoll]++;
                arrNumOccurrence[fourRoll]++;
                arrNumOccurrence[fiveRoll]++;
                arrNumOccurrence[sixRoll]++;
                arrNumOccurrence[sevenRoll]++;
                arrNumOccurrence[eightRoll]++;
                arrNumOccurrence[nineRoll]++;
                arrNumOccurrence[tenRoll]++;
                arrNumOccurrence[elevenRoll]++;
                arrNumOccurrence[twelveRoll]++;
                arrNumOccurrence[thirteenRoll]++;
                arrNumOccurrence[fourteenRoll]++;
            }
            string rolls = "";
            for (int i = 1; i < numrolls; i++)
            {
                Random random = new Random(1);
                i = random.Next(1, 7) + random.Next(1, 7);
                rolls = rolls + i;

            }
            MessageBox.Show(rolls + "\t" + rolls );
            numTimes.Text = "# of Times\n" + arrNumOccurrence[2]++ + "\n" + arrNumOccurrence[3]++ + "\n" + arrNumOccurrence[4]++ + "\n" + arrNumOccurrence[5]++ + "\n" + arrNumOccurrence[6]++ + "\n" + arrNumOccurrence[7]++ + "\n" + arrNumOccurrence[8]++ + "\n" + arrNumOccurrence[9]++ + "\n" + arrNumOccurrence[10]++ + "\n" + arrNumOccurrence[11]++ + "\n" + arrNumOccurrence[12]++ + "\n";
            // Now This tallys the thing that happens only once


        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void diceRoll_Load(object sender, EventArgs e)
        {

        }
    }
}

As you can see there is a lot of stupid stuff in it. The only thing I can’t do is make the random number generator occur, using one name, the number of times the user wants. This is a Windows Forms application.

You can see that I called them oneRoll and twoRoll and so on so I get different values but I want oneRoll to occur as many times as a user wants and to give different numbers.

  • 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-05-24T03:06:07+00:00Added an answer on May 24, 2026 at 3:06 am

    Right – so you need a collection of some form. For example:

    List<int> rolls = new List<int>();
    
    for (int i = 0; i < desiredRolls; i++)
    {
        rolls.Add(randGen.Next(1, 7) + randGen.Next(1, 7));
    }
    

    Then do whatever else you need to in a similar way, looping. You may not even need to store all the rolls – if you’re just incrementing the occurences, you could use:

    for (int i = 0; i < desiredRolls; i++)
    {
        int roll = randGen.Next(1, 7) + randGen.Next(1, 7);
        arrNumOccurrence[roll]++;
    }
    

    Basically it’s not clear exactly what your assignment is, but a mixture of collections and for loops is likely to get you on the right track.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to simulate N-sided biased die? def roll(N,bias): '''this function rolls N dimensional
I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should
The throw of a die is a popular program in Java, public class Die
This is my code: <?php mysql_connect(localhost,*****,********) or die(Can't connect to DB); mysql_select_db(kroltan_main) or die(Can't
all i want block of code wait for another thread to die where this
Running ActiveState Perl 5.10.1 on win32. How is it that this code: die(defined($r->unparsed_uri =~
This code works fine, but each time i look at it, i die a
Given the following code (and only this code): <?php if (headers_sent()) { die('cannot send
$query1 = SELECT * FROM idevaff_affiliates; $affiliateID = mysql_query($query1) or die(mysql_error()); This is my
Consider this trivial example of fork() ing then waiting for a child to die

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.