So this is what I would like to do. I am kind of all over the place with this but I hope you can bear with me. This is a very new concept to me.
1) In my program I wish create an array of 50 integers to hold the data that comes from the file. My program must get the path to the user's Documents folder. 2) The name of the file will be "grades.txt". Code this file name right in your program. No user input is required to get the file name. 3) Create a StreamReader object, using this path. This will open the file. Write a loop that reads data from the file, until it discovers the end of the file. 4) As each integer value is read in, I display it, and store it in the array. 5) Using the concepts of partially filled arrays, write a method that takes the array as a parameter and calculates and returns the average value of the integers stored in the array Output the average.
So right now I am having a very hard time figuring out how to get the numbers saved in the grades.txt file, save them to an array, and display them. I try to split the integers and save them as that but it doesn't seem to work.
This is the code that I have so far:
class Program
{
const int SIZE = 50;
static void Main()
{
// This line of code gets the path to the My Documents Folder
int zero = 0;
int counter = 0;
int n, m;
StreamReader myFile;
myFile = new StreamReader("C:/grades.txt");
string inputNum = myFile.ReadLine();
do
{
Console.Write("The test scores are listed as follows:");
string[] splitNum = myFile.Split();
n = int.Parse(splitNum[0]);
{
if (n != zero)
{
Console.Write("{0}", n);
counter++;
}
}
} while (counter < SIZE && inputNum != null);
// now we can use the full path to get the document
Console.ReadLine();
}
}
This is the grades.Txt file:
88
90
78
65
50
83
75
23
60
94