0

Im trying to make a seating chart and the way im going about it doesn't seem to be working and i really need some help with assigning a value (each value will be a seat number on a little chart i made) to a variable (a students name). The problem i keep having is im trying to use a list to store what seats (numbers) i already have assigned to one student. Then if the seat value is already in the list, it should go back to get a new value and the repeat the checking process to see if the new value is taken and so on. in python it would just be something as simple as

def main():
    x = Random.randint(1,20)
    main()     <----this go back to type function is what i need to know in c#

below is my code in c#

public void Button_Click(object sender, EventArgs e)
    {






        int a = getValue();
        int b = getValue();
        int c = getValue();
        int d = getValue();
        int ee = getValue();
        int f = getValue();
        int g = getValue();
        int h = getValue();
        int i = getValue();
        int ff = getValue();
        int gg = getValue();
        int hh = getValue();
        int ii = getValue();
        int j = getValue();
        int k = getValue();
        int l = getValue();
        int m = getValue();
        int n = getValue();
        int o = getValue();
        int p = getValue();
        int q = getValue();
        int r = getValue();
        int s = getValue();
        int t = getValue();
        int u = getValue();
        int v = getValue();
        int w = getValue();
        int x = getValue();
        int y = getValue();
        int z = getValue();
        int AA = getValue();
        int BB = getValue();


        Dictionary<string, int> studentNames = new Dictionary<string, int>();
        studentNames.Add("a", a);//1
        studentNames.Add("b", b);
        studentNames.Add("c", c);
        studentNames.Add("d", d);
        studentNames.Add("e", ee);
        studentNames.Add("f", ff);
        studentNames.Add("g", gg);
        studentNames.Add("h", hh);
        studentNames.Add("i", ii);//9
        studentNames.Add("j", j);
        studentNames.Add("k", k);
        studentNames.Add("l", l);
        studentNames.Add("m", m);
        studentNames.Add("n", n);
        studentNames.Add("o", o);
        studentNames.Add("p", p);
        studentNames.Add("q", q);
        studentNames.Add("r", r);
        studentNames.Add("s", s);
        studentNames.Add("t", t);//20
        studentNames.Add("u", u);
        studentNames.Add("v", v);
        studentNames.Add("w", w);
        studentNames.Add("x", x);
        studentNames.Add("y", y);
        studentNames.Add("z", z);
        studentNames.Add("AA", AA);
        studentNames.Add("BB", BB);//28
    }

    public int getValue()
    {
        List<int> usedNumbers = new List<int>();
        Random rnd = new Random();
        int tempValue = rnd.Next(0, 27);

        if (usedNumbers.Contains(tempValue))
        {

// Go back to getValue() to have the tempValue get a new value
        }
        else
        {
             usedNumbers.Add(tempValue);
             return tempValue;
        }
    }
}
SpenceK
  • 1
  • 3
  • 2
    You can't generate 26 unique random integers between 1 and 20.... – Servy Dec 17 '15 at 15:45
  • Better make a list of integers representing the free places and then remove from this list until you have exausted the places – Steve Dec 17 '15 at 15:50
  • servy, the portion of python code was just to show an example of a looping function which is what i really want to know how to do in c#, that is if i can. if not o well ill try and use the http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp thread to solve my problem – SpenceK Dec 17 '15 at 15:59

0 Answers0