Click here to Skip to main content
15,791,771 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# forms Pin
Tim Groven8-May-12 6:58
Tim Groven8-May-12 6:58 
AnswerRe: C# forms Pin
Reegan Durai.m8-May-12 20:16
Reegan Durai.m8-May-12 20:16 
QuestionC# dice program (combobox selection) Pin
Angel_788-May-12 2:19
Angel_788-May-12 2:19 
AnswerRe: C# dice program (combobox selection) Pin
Jeremy Hutchinson8-May-12 4:01
professionalJeremy Hutchinson8-May-12 4:01 
GeneralRe: C# dice program (combobox selection) Pin
Angel_788-May-12 4:37
Angel_788-May-12 4:37 
GeneralRe: C# dice program (combobox selection) Pin
BobJanova8-May-12 5:38
BobJanova8-May-12 5:38 
AnswerRe: C# dice program (combobox selection) Pin
PIEBALDconsult8-May-12 4:12
professionalPIEBALDconsult8-May-12 4:12 
GeneralRe: C# dice program (combobox selection) Pin
Angel_788-May-12 4:50
Angel_788-May-12 4:50 
I don't think I got that. I have a comboBox and added 3 sided dice, 4 sided dice etc. using, skipped the design mode and just put it into the form, the code now looks like this.
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 Dice
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            comboBox1.Items.Add("3 sided die");
            comboBox1.Items.Add("4 sided die");
            comboBox1.Items.Add("5 sided die");
            comboBox1.Items.Add("6 sided die");
            comboBox1.DisplayMember = "Name";
            comboBox1.ValueMember = "Value";

        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            // Initiate class
            var random = new RollDice();
            // Call method
            var dice =
            
            // Store value
            int result;
            // Call value
            result = ();
            // Numeric value to a textbox
            richTextBox1.Text = (result).ToString();
        }
    }
    public class RollDice
    {
        public static int RandomDice(Int32 numberOfSides, Int32 numberOfTimes)
        {
            int total = 0;
 
            Random rndGen = new Random((int)DateTime.Now.Ticks);
 
            for (int i = 0; i < numberOfTimes; i++)
            {
                // Upperbound is exclusive so add 1 to the number of sides
                total = total + rndGen.Next(1, numberOfSides + 1);
            }
            return total;
        }    
    }
}

I am unsure how to assign "3 sided die" the value of 3, on my button click take the selected value in the comboBox1 (numberOfSides) + (numberOfTimes) from my textBox1 and call the method.

Some code in here is incomplete, the call method part and comboBox items has 0 value
GeneralRe: C# dice program (combobox selection) Pin
PIEBALDconsult8-May-12 19:39
professionalPIEBALDconsult8-May-12 19:39 
GeneralRe: C# dice program (combobox selection) Pin
Angel_789-May-12 3:55
Angel_789-May-12 3:55 
GeneralRe: C# dice program (combobox selection) Pin
PIEBALDconsult9-May-12 4:20
professionalPIEBALDconsult9-May-12 4:20 
GeneralRe: C# dice program (combobox selection) Pin
Angel_789-May-12 6:53
Angel_789-May-12 6:53 
GeneralRe: C# dice program (combobox selection) Pin
PIEBALDconsult10-May-12 4:09
professionalPIEBALDconsult10-May-12 4:09 
GeneralRe: C# dice program (combobox selection) Pin
Angel_7810-May-12 7:07
Angel_7810-May-12 7:07 
GeneralRe: C# dice program (combobox selection) Pin
PIEBALDconsult10-May-12 16:48
professionalPIEBALDconsult10-May-12 16:48 
GeneralRe: C# dice program (combobox selection) Pin
Angel_7811-May-12 16:57
Angel_7811-May-12 16:57 
GeneralRe: C# dice program (combobox selection) Pin
PIEBALDconsult12-May-12 7:23
professionalPIEBALDconsult12-May-12 7:23 
GeneralRe: C# dice program (combobox selection) Pin
Angel_7812-May-12 13:12
Angel_7812-May-12 13:12 
GeneralRe: C# dice program (combobox selection) Pin
PIEBALDconsult13-May-12 6:31
professionalPIEBALDconsult13-May-12 6:31 
GeneralRe: C# dice program (combobox selection) Pin
Angel_7813-May-12 11:09
Angel_7813-May-12 11:09 
GeneralRe: C# dice program (combobox selection) Pin
PIEBALDconsult13-May-12 17:34
professionalPIEBALDconsult13-May-12 17:34 
GeneralRe: C# dice program (combobox selection) Pin
Angel_7814-May-12 11:36
Angel_7814-May-12 11:36 
GeneralRe: C# dice program (combobox selection) Pin
PIEBALDconsult14-May-12 15:11
professionalPIEBALDconsult14-May-12 15:11 
Questionerror on exiting form wit datagridview containing comboboxcell Pin
markoVVVV8-May-12 2:14
markoVVVV8-May-12 2:14 
AnswerRe: error on exiting form wit datagridview containing comboboxcell Pin
Eddy Vluggen8-May-12 6:03
professionalEddy Vluggen8-May-12 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.