Thread: Brickwall - Help

  1. #1
    Registered User
    Join Date
    Mar 2011
    Location
    a wasteland, more commonly known as Hull
    Posts
    3

    Brickwall - Help

    It's as the title says, I've hit a brickwall and have no idea how I'm suppose to get round it. The programme is for solving Algorithms, we've got 3 different search codes to implement. I've been able to iron out the majority of errors but now the code doesn't refference the text file and it keeps coming up saying that it cannnot run. Here's the code if you wanna take a look;
    Code:
    using System;
    using System.Text;
    using ClassLibrary1;
    using System.IO;
    
    
    namespace ProfitCalculator
    {
        public class RangeFinder
        {
            /// <summary>
            /// Performs a search to find the start and end of the "best" period and the
            /// total amount of sales over that period.
            /// </summary>
            /// <param name="data">the data to be examined</param>
            /// <param name="bestStart">the start point found by the search</param>
            /// <param name="bestEnd">the end point found by the search</param>
            /// <param name="bestTotal">the total sales over that period</param>
            /// <param name="loops">the number of executions of the inner loop</param>
            public static void Search(double[] data, out int bestStart,
            out int bestEnd, out double bestTotal, out int loops)
            {
                bestTotal = 0;
                bestStart = 0;
                bestEnd = 0;
                loops = 0;
                // For every possible start position // every array index
                // For every possible end position // rest of array from current start
                {
                    // Set subtotal to 0
                    // For every value in subseq // between current start and end
                    // Add profit value to subtotal
                    // Update subseq info when subtotal exceeds current best total
                }
                {
                    for (int i = 0; i < 52; i++)
                    {
                        Console.WriteLine("Value [52]", data[i]);
                    }
                }
            }
    
    
            /// <summary>
            /// Tests the Profits Calculator
            /// </summary>
            class Test
            {
                /// <summary>
                /// The main entry point for the application.
                /// </summary>
                static void Main()
                {
                    double[] data;
                    int bestStart, bestEnd;
                    double bestTotal;
                    int loops;
                    /// continue reading Week52.txt until you have reached the end of the file
                    string filename = "week52.txt";
                    int items = 52;
                    data = new double[items];
                    try
                    {
                        System.IO.TextReader textIn = new StreamReader(filename);
                        for (int i = 0; i < items; i++)
                        {
                            string line = textIn.ReadLine();
                            data[i] = double.Parse(line);
                        }
                        textIn.Close();
                    }
                    catch
                    {
                        Console.WriteLine("File Read Failed");
                        return;
                    }
                    RangeFinder.Search(
                    data, out bestStart, out bestEnd, out bestTotal, out loops);
                    Console.WriteLine("Start : {0} End : {1} Total {2} Loops {3}",
                    bestStart, bestEnd, bestTotal, loops);
                }
            }
        }
    }
    And here's the text file;
    -31.33
    17.83
    4.4
    -37.99
    -13.87
    -48.72
    37.08
    -16.48
    5.25
    -36.21
    -3
    8.47
    -0.04
    -35.78
    -1.36
    -41.1
    34.31
    33.82
    -36.82
    11.62
    -36.31
    -45.07
    -47.99
    2.62
    40.78
    31.5
    24.82
    -35.05
    -46.4
    0.36
    17.55
    -7.56
    7.32
    14.16
    12.95
    2.93
    -13.65
    -13.51
    -29.79
    2.9
    -17.37
    -4.71
    16.39
    -1.09
    -24.62
    -41.38
    -18.41
    -32.98
    36.87
    -44.26
    6.6
    40.68

    Please, any help would be appreciated.

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    Is the text file in the same directory as the executable? What message does the program give you when you try to run it?

    There are errors in your program that don't affect if it will run, though.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Location
    a wasteland, more commonly known as Hull
    Posts
    3
    It no longer comes up with the message, now though it just prints out the Console.WriteLine message "file read failed". You're right though, must be errors I haven't spotted. The text file currently resides in the resources file of the code.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    Your code is looking for the file to be in the same directory as the executable, so I'd put it there.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Location
    a wasteland, more commonly known as Hull
    Posts
    3
    This gonna sound daft but how do you do that?

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    Find the text file in windows explorer. Right click on it and select 'copy'. Navigate to the appropriate directory where your executable is. Right click and select 'paste'.

Popular pages Recent additions subscribe to a feed