Click here to Skip to main content
15,880,972 members
Home / Discussions / C#
   

C#

 
GeneralRe: Doubt Pin
Xmen Real 11-Mar-09 5:19
professional Xmen Real 11-Mar-09 5:19 
GeneralRe: Doubt Pin
CPallini11-Mar-09 4:54
mveCPallini11-Mar-09 4:54 
GeneralRe: Doubt Pin
Xmen Real 11-Mar-09 5:12
professional Xmen Real 11-Mar-09 5:12 
GeneralRe: Doubt Pin
harold aptroot11-Mar-09 5:16
harold aptroot11-Mar-09 5:16 
AnswerRe: Doubt Pin
Ennis Ray Lynch, Jr.11-Mar-09 8:48
Ennis Ray Lynch, Jr.11-Mar-09 8:48 
Questionhow can I show the file path instead of ref Pin
wwwxyz11-Mar-09 1:32
wwwxyz11-Mar-09 1:32 
AnswerRe: how can I show the file path instead of ref Pin
wwwxyz11-Mar-09 2:16
wwwxyz11-Mar-09 2:16 
GeneralRe: how can I show the file path instead of ref [modified] Pin
Rutvik Dave11-Mar-09 4:22
professionalRutvik Dave11-Mar-09 4:22 
Your Working Program

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Program app = new Program();
            Console.ReadLine();
        }

        Program()
        {
            bool ok = false;
            double[] w = new double[25];
            double[] l = new double[25];
            double[] u = new double[25];
            double[] z = new double[25];
            double ft = 0.0, fx = 0.0, alpha = 0.0, h = 0.0, k = 0.0, vv = 0.0, t = 0.0, x = 0.0;
            int n = 0, m = 0, m1 = 0, m2 = 0, n1 = 0, flag = 0, i1 = 0, i = 0, j = 0;
            input(ref ok, ref fx, ref ft, ref alpha, ref n, ref m);

            if (ok)
            {
                m1 = m - 1;
                m2 = m - 2;
                //    n1 = n - 1;
                /* step 1 */
                h = fx / m;
                k = ft / n;
                vv = alpha * k / (h * h);
                /* step 2 */
                for (i = 1; i <= m1; i++) w[i - 1] = F(i * h);
                /* step 3 */
                l[0] = 1.0 - 2.0 * vv;
                u[0] = vv / l[0];
                /* step 4 */
                for (i = 2; i <= m2; i++)
                {
                    l[i - 1] = 1.0 - 2.0 * vv - vv * u[i - 2];
                    u[i - 1] = vv / l[i - 1];
                }
                /* step 5 */
                l[m1 - 1] = 1.0 - 2.0 * vv - vv * u[m2 - 1];
                /* step 6 */
                for (j = 1; j <= n; j++)
                {
                    /* step 7 */
                    /* current t(j) */
                    //   t = j * k;
                    z[0] = w[0] / l[0];
                    /* step 8 */

                    for (i = 2; i <= m1; i++)
                        z[i - 1] = (w[i - 1] - vv * z[i - 2]) / l[i - 1];
                    /* step 9 */
                    w[m1 - 1] = z[m1 - 1];
                    /* step 10 */
                    for (i1 = 1; i1 <= m2; i1++)
                    {
                        i = m2 - i1 + 1;
                        w[i - 1] = z[i - 1] - u[i - 1] * w[i];
                    }
                }
                /* step 11 */
                output(ft, x, m1, ref w, h);
            }

        }


        private double F(double X)
        {
            double f;
            f = 0.3061 * X * X - 2.1286 * X + 38.11;
            return f;
        }

        private void input(ref bool ok, ref double fx, ref double ft, ref double alpha, ref int n, ref int m)
        {
            try
            {
                FileStream fs = new FileStream("D:\\a.txt", FileMode.Open);
                StreamReader sr = new StreamReader(fs);

                string[] lines = new string[10]; // you cannot use list like that
                string line;
                //add all the lines to a list
                int i = 0;
                while ((line = sr.ReadLine()) != null)
                {
                    lines[i++] = (line);
                }
                //read the lines you would like to read:
                try
                {
                    fx = double.Parse(lines[1]);
                    ft = double.Parse(lines[2]);
                    alpha = double.Parse(lines[3]);
                    m = Int32.Parse(lines[4]);
                    n = Int32.Parse(lines[5]);
                }
                catch { }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in ShowFile: {0}", e);
            }
            ok = true;
        }

        public void output(double ft, double x, int m1, ref double[] w, double h)
        {
            System.IO.StreamWriter oup;
            System.IO.TextWriter tmp = Console.Out;
            Console.WriteLine("Choice of output method.");
            Console.WriteLine("1. Output to screen");
            Console.WriteLine("2. Output to text file");
            int flag = Convert.ToInt32(Console.ReadLine());
            if (flag == 2)
            {

                Console.WriteLine("Sample:   C:\\Data\\1.txt");
                string name = Console.ReadLine();
                try
                {
                    name = name.Replace(@"\",@"\\"); // look at the changes in the path
                    oup = new System.IO.StreamWriter(name);
                    Console.SetOut(oup);
                    write(ft, x, m1, ref w, h);
                    oup.Close();
                }
                catch (System.IO.IOException expc)
                {
                    Console.WriteLine(expc.Message + " file dont extract.");
                }
            }
            else
            {
                write(ft, x, m1, ref w, h);
            }


        }

        private void write(double ft, double x, int m1, ref double[] w, double h)
        {

            Console.WriteLine("I\tX(I)\tW(X(I),{0:#.#})", ft);
            for (int i = 1; i <= m1; i++)
            {
                x = i * h;
                Console.WriteLine("{0:#.##}\t{1:#.###}\t\t{2:#.###}", i, x, w[i - 1]);
            }
        }
    }
}



You cannot use List without parameter, or you can use string array.
You forgot to set ok = true; in the input();
You have to replace \ with \\ in "name" (path) to make it working

never use anonymous try-catch block (means empty "catch {}" ). because of that you are not getting any error. so dont use that. always catch it with some message.

modified on Wednesday, March 11, 2009 10:41 AM

GeneralRe: how can I show the file path instead of ref Pin
wwwxyz11-Mar-09 5:10
wwwxyz11-Mar-09 5:10 
AnswerRe: how can I show the file path instead of ref Pin
musefan11-Mar-09 2:36
musefan11-Mar-09 2:36 
GeneralRe: how can I show the file path instead of ref Pin
wwwxyz11-Mar-09 2:44
wwwxyz11-Mar-09 2:44 
RantRe: how can I show the file path instead of ref Pin
Nagy Vilmos11-Mar-09 2:55
professionalNagy Vilmos11-Mar-09 2:55 
GeneralRe: how can I show the file path instead of ref Pin
musefan11-Mar-09 3:03
musefan11-Mar-09 3:03 
GeneralRe: how can I show the file path instead of ref Pin
Nagy Vilmos11-Mar-09 3:08
professionalNagy Vilmos11-Mar-09 3:08 
GeneralRe: how can I show the file path instead of ref Pin
musefan11-Mar-09 3:11
musefan11-Mar-09 3:11 
GeneralRe: how can I show the file path instead of ref Pin
Dave Kreskowiak11-Mar-09 4:17
mveDave Kreskowiak11-Mar-09 4:17 
GeneralRe: how can I show the file path instead of ref Pin
Nagy Vilmos11-Mar-09 4:24
professionalNagy Vilmos11-Mar-09 4:24 
GeneralRe: how can I show the file path instead of ref Pin
#realJSOP11-Mar-09 3:19
mve#realJSOP11-Mar-09 3:19 
GeneralRe: how can I show the file path instead of ref Pin
wwwxyz11-Mar-09 3:43
wwwxyz11-Mar-09 3:43 
AnswerRe: how can I show the file path instead of ref Pin
Nagy Vilmos11-Mar-09 4:23
professionalNagy Vilmos11-Mar-09 4:23 
GeneralRe: how can I show the file path instead of ref Pin
wwwxyz11-Mar-09 4:43
wwwxyz11-Mar-09 4:43 
GeneralRe: how can I show the file path instead of ref Pin
Nagy Vilmos11-Mar-09 4:46
professionalNagy Vilmos11-Mar-09 4:46 
GeneralRe: how can I show the file path instead of ref Pin
#realJSOP11-Mar-09 4:50
mve#realJSOP11-Mar-09 4:50 
GeneralRe: how can I show the noobie the path instead of the knife? Pin
Nagy Vilmos11-Mar-09 5:12
professionalNagy Vilmos11-Mar-09 5:12 
GeneralRe: how can I show the file path instead of ref Pin
fly90411-Mar-09 11:29
fly90411-Mar-09 11:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.