Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have my code running, but it is still not outputting the numbers in the order

ID: 645028 • Letter: I

Question

I have my code running, but it is still not outputting the numbers in the order they should be in. So here is what it should be outputting:

Actors Count Audition Order

1 1 1

2 1 1 2
2 2 2 1

3 1 1 2 3
3 2 2 1 3
3 3 3 1 2

4 1 1 2 3 4
4 2 2 4 3 1
4 3 3 2 4 1
4 4 4 1 3 2

5 1 1 2 3 4 5
5 2 2 4 1 5 3
5 3 3 1 5 2 4
5 4 4 3 5 2 1
5 5 5 1 3 4 2

6 1 1 2 3 4 5 6
6 2 2 4 6 3 1 5
6 3 3 6 4 2 5 1
6 4 4 2 1 3 6 5
6 5 5 4 6 2 3 1
6 6 6 1 3 2 5 4

7 1 1 2 3 4 5 6 7
7 2 2 4 6 1 5 3 7
7 3 3 6 2 7 5 1 4
7 4 4 1 6 5 7 3 2
7 5 5 3 2 4 7 1 6
7 6 6 5 7 2 1 4 3
7 7 7 1 3 6 2 4 5

8 1 1 2 3 4 5 6 7 8
8 2 2 4 6 8 3 7 5 1
8 3 3 6 1 5 2 8 4 7
8 4 4 8 5 2 1 3 7 6
8 5 5 2 8 7 1 4 6 3
8 6 6 4 3 5 8 7 2 1
8 7 7 6 8 2 5 1 3 4
8 8 8 1 3 6 5 2 7 4

9 1 1 2 3 4 5 6 7 8 9
9 2 2 4 6 8 1 5 9 7 3
9 3 3 6 9 4 8 5 2 7 1
9 4 4 8 3 9 6 5 7 2 1
9 5 5 1 7 4 3 6 9 2 8
9 6 6 3 1 9 2 5 4 8 7
9 7 7 5 4 6 9 3 8 1 2
9 8 8 7 9 2 5 4 1 6 3
9 9 9 1 3 6 4 5 2 7 8

Mine outputs correctly until it hits actor 4.

Here is my code:

using System;

using System.Collections;

using System.Text;

namespace The_Last_Survivor

{

class Program

{

static void Main(string[] args)

{

Console.Out.WriteLine("The Last Survivor");

Console.Out.WriteLine("Author: Laura Bullard");

Console.Out.WriteLine("Date: March 18, 2015");

Console.Out.WriteLine("Course: GSD311 - C# Programming");

Console.Out.WriteLine("Assignment: Seminar 4 Individual Program ");

Console.Out.WriteLine("A group of actors waits in a circle. They count");

Console.Out.WriteLine("off by various amounts. The last few to audition");

Console.Out.WriteLine("are thought to have the best chance of getting the");

Console.Out.WriteLine("parts and becoming stars. ");

Console.Out.WriteLine("Instead of actors having names, they are identified");

Console.Out.WriteLine("by numbers. The Audition Order in the table tells,");

Console.Out.WriteLine("reading left-to-right, the names of the actors who");

Console.Out.WriteLine("will be auditioned in the order they will perform. ");

Console.Out.WriteLine("Actors Count Audition Order");

  

int actorsNum = 0;

System.DateTime dt = System.DateTime.Now;

int interval = 0;

ArrayList Ring = new ArrayList(9);

for (int x = 1; x < 10; x++)

{

actorsNum++;

Ring.Insert((x - 1), new Actor(x));

foreach (Actor act in Ring)

{

interval = interval + 1;

  

Console.Out.WriteLine("{0} {1} {2}", actorsNum, act, act.Order(interval, x));

}

Console.Out.WriteLine(" ");

}

Console.In.ReadLine();

}

// Actors individual number

public class Actor

{

  

protected int number;

public Actor(int num)

{

number = num;

}

// Outputs the actors line orders after while statement is complete

public string Order(int inter, int num)

{

string result = "";

int p = 2;

ArrayList myArray = new ArrayList(num);

  

for (int i = 0; i < num; i++)

myArray.Add(i + 1);

// Calculates actors order in line

while (myArray.Count > 1)

{

p = (p + inter) % myArray.Count;

result += (myArray[p] + " ");

myArray.RemoveAt(p);

}

result += (myArray[0]);

myArray.Clear();

return result;

}

  

public override string ToString()

{

return String.Format("{0}", number);

}

}

}

}

Explanation / Answer

using System;
using System.Collections;
using System.Text;

namespace The_Last_Survivor
{
    class Program
    {
        static void Main(string[] args)
        {

            int NumOfActors = 0;
            System.DateTime dt = System.DateTime.Now;
            int interval = 3;
            ArrayList Ring = new ArrayList(10);


            Console.Out.WriteLine("Actors Number Order");


            for (int x = 1; x < 11; x++)
            {
                NumOfActors++;

                Ring.Insert((x - 1), new Actor(x));

                foreach (Actor i in Ring)
                {
                    Console.Out.WriteLine("{0} {1} {2}", NumOfActors, i, i.Order(interval, x));
                }

                Console.Out.WriteLine(" ");
            }

            Console.In.Read();
        }

        public class Actor
        {

            protected int Number;


            public Actor(int num)
            {
                Number = num;
            }


            public string Order(int inter, int num)
            {

                string result = "";
                ArrayList myArray = new ArrayList(num);

                for (int i = 0; i < num; i++)
                    myArray.Add(i + 1);

             
                foreach (int element in myArray)
                {
                    if (element == inter)
                    {
                        result += String.Format(" {0}", element);
                        myArray.RemoveAt(element);
                    }
                }
                return result;
            }

         
            public override string ToString()
            {
                return String.Format("{0}", Number);
            }
        }
    }
}