Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-27-2006, 04:20 PM   #1 (permalink)
sadinger
Registered User
 
sadinger's Avatar
 
Join Date: Mar 2006
Location: Louisiana
Posts: 3
sadinger is on a distinguished road
Question Problem using System.IO, Please Help

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.

Last edited by redhead; 04-28-2006 at 09:44 AM.
sadinger is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
parse error problem in game.. can't seem to find problem solution. slashdot Standard C, C++ 5 08-03-2005 08:15 PM
JSP code problem j.gohel Java 7 04-15-2005 02:07 PM
Hashing problem jodders Standard C, C++ 1 02-09-2005 01:51 PM
Problem Assignment (Urgent help req.) Boltress Standard C, C++ 0 01-12-2005 07:59 AM
Help debugging a power problem Belisarius Lounge 0 10-25-2003 04:44 PM


All times are GMT -8. The time now is 02:29 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting