Ok, so if I am following correctly then do I want my code to be:
Code:
Console.WriteLine("{0} : {1}", i + offset, frequencies[i]);
Freqbox.Add();
If so I am still getting the error that it does not contain a definition for 'Add'. I don't want to add it to the Designer codes do I?
Here is my entire code right now if you need to see it:
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[11];
int offset = 2; //frequencies[2] is the frequency of the sum 2, frequencies[12] is for sum 12
for (int i = 0; i < 5; i++)
{
//Sets the dice to roll a random number
firstDice = randomNumber.Next(1, 6);
secondDice = randomNumber.Next(1, 6);
//Adds the values of the two dice
sum = firstDice + secondDice;
this.RollSumbox.Items.Add(
String.Format("1 Dice = {0}\t2 Dice = {1}\tSum = {2}", firstDice, secondDice, sum));
frequencies[sum]++;
}
// TODO - display the frequencies array elements as listbox2 items
for (int i = 0; i<11; i++)
Console.WriteLine("{0} : {1}", i + offset, frequencies[i]);
Freqbox.Add();
}
}
}
And here is the code from the Designer:
Code:
namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.RollDicebtn = new System.Windows.Forms.Button();
this.RollSumbox = new System.Windows.Forms.ListBox();
this.Freqbox = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// RollDicebtn
//
this.RollDicebtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.RollDicebtn.Location = new System.Drawing.Point(78, 25);
this.RollDicebtn.Name = "RollDicebtn";
this.RollDicebtn.Size = new System.Drawing.Size(285, 81);
this.RollDicebtn.TabIndex = 0;
this.RollDicebtn.Text = "Roll Dice and Display";
this.RollDicebtn.UseVisualStyleBackColor = true;
this.RollDicebtn.Click += new System.EventHandler(this.RollDicebtn_Click);
//
// RollSumbox
//
this.RollSumbox.FormattingEnabled = true;
this.RollSumbox.Location = new System.Drawing.Point(78, 140);
this.RollSumbox.Name = "RollSumbox";
this.RollSumbox.Size = new System.Drawing.Size(285, 134);
this.RollSumbox.TabIndex = 1;
//
// Freqbox
//
this.Freqbox.FormattingEnabled = true;
this.Freqbox.Location = new System.Drawing.Point(78, 304);
this.Freqbox.Name = "Freqbox";
this.Freqbox.Size = new System.Drawing.Size(285, 134);
this.Freqbox.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(457, 467);
this.Controls.Add(this.Freqbox);
this.Controls.Add(this.RollSumbox);
this.Controls.Add(this.RollDicebtn);
this.Name = "Form1";
this.Text = "Everett- Dice Sum Frequencies";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button RollDicebtn;
private System.Windows.Forms.ListBox RollSumbox;
private System.Windows.Forms.ListBox Freqbox;
}
}