Results 1 to 40 of 43

Thread: [RESOLVED] Sum Frequency Trouble

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2012
    Posts
    51

    Resolved [RESOLVED] Sum Frequency Trouble

    Hello Everyone,

    I am creating a program that rolls two dice 5 times and adds the values together. This information is shown in a listbox. The issue I am having is that I need the frequency of the sums to show in a second listbox. I have been searching everywhere and am having trouble finding something that will work. Here is the code for the program I have so far:
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void RollDicebtn_Click(object sender, EventArgs e)
            {
                int firstDice = 0;
                int secondDice = 0;
                int sum = 0;
                Random randomNumber = new Random();
                int[] frequencies = new int[13]; //frequencies[2] is the frequency of the sum 2, frequencies[12] is for sum 12
    
                for (int i = 0; i < 5; i++)
                {
                    firstDice = randomNumber.Next(1, 6);
                    secondDice = randomNumber.Next(1, 6);
                    sum = firstDice + secondDice;
                    this.RollSumbox.Items.Add(
                        String.Format("1 Dice = {0}\t2 Dice = {1}\tSum = {2}", firstDice, secondDice, sum));
                    frequencies[sum]++;
                }
            }
        }
    }
    I need help with how to get the frequencies of the sums to appear in the second box. I am not asking for the codes to be done for me, I just need an example or something to get me started in the right direction. Like I said before, I have been searching everywhere with how to do this and nothing seems to be working for me. I am also attaching an image of the program running to help give you an idea of what I am doing.
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width