My list is not being written to the outFile and I can't seem to figure out why. I will post the code but I am not sure how to paste it correctly. Any Help would be appreciated.
Code:
using System;
using System.IO;
namespace Seating_Chart
/*Write a C# program that will read a list of student
* names from a text fileand assemble a seating chart
* onscreen.When the program is first run it should
* display an empty seating grid.Then you should be
* able to change the seating of any student. Such
* as Row 1, Seat 4 and change it's name to "John Doe".
* Any changes made should be immediatley written to
* the file.You must use more than one class. */
{
class Students
{
static void Main ()
{
string [,] Students = new string [5,10];
char answer = ' ';
int row = 0;
int seat = 0;
SeatChange NewSeatChange = new SeatChange();
StreamReader inStream = null;
StreamWriter outStream = null;
FileInfo inFile = new FileInfo (@"Student Seating Chart.txt");
FileInfo outFile = new FileInfo (@"Student Seating Chart.txt");
inStream = inFile.OpenText();
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 10; y++)
{
Students [x, y]=inStream.ReadLine();
}
}
inStream.Close();
for (int x = 0; x < 5; x++)
{
Students [x, 0]=Convert.ToString(x);
}
for (int y = 0; y < 10; y++)
{
Students [0, y]=Convert.ToString(y);
}
Console.WriteLine ("Seat 1 2 3 4 5 6 7 8 9 10");
Console.WriteLine (" ----------------------------------------");
for (int x = 0; x < 5; x++)
{
Console.Write ("ROW " + (x + 1) + " ");
for (int y = 0; y < 10; y++)
{
Console.Write (" ", Students[x,y]);
}
Console.WriteLine ();
Console.WriteLine();
}
do
{
outStream = outFile.CreateText();
Console.WriteLine("Please enter the Row Number of the student you wish to move: ");
row = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter the Seat number of the student you want to move;");
seat = Convert.ToInt32(Console.ReadLine());
Students = NewSeatChange.Change(Students,seat,row);
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 10; y++)
{
outStream.WriteLine(Students [x, y]);
}
}
outStream.Close();
Console.WriteLine ("seat 1 2 3 4 5 6 7 8 9 10");
Console.WriteLine (" ----------------------------------------");
for (int x = 0; x < 5; x++)
{
Console.Write ("ROW " + (x + 1) + " ");
for (int y = 0; y < 10; y++)
{
Console.Write (" ", Students[x,y]);
}
Console.WriteLine ();
Console.WriteLine();
}
Console.WriteLine("Would you like to move another student?");
answer = Convert.ToChar(Console.ReadLine());
}while(answer == 'y');
}
}
class SeatChange
{
public string [ , ] Change(string[ , ] Students, int a, int b)
{
Console.WriteLine("Please enter the students name:");
Students[a,b] = Console.ReadLine();
return Students;
}
}
}
Sorry this is so messy.
//edit, adding some [code ][/code ] blocks around it helps a bit.