How to add up amount of data from an external file in C# (Stream Reader)

Posted by user2985995 on Stack Overflow See other posts from Stack Overflow or by user2985995
Published on 2013-11-13T03:45:46Z Indexed on 2013/11/13 3:53 UTC
Read the original article Hit count: 116

Filed under:
|
|
|
|

I'm new to this site, and pretty new to programming, at the moment I'm trying to display a count amount for the users names on my donation list, and then I also want to have a sum to work out the total amount of money the donation list contains, If someone could help me with creating a way to add up amount of donors on the donations.txt file that would be great help, I have no idea where to start, but so far this is my coding:

        string sName;
        double dAmount;
        string sTotalNames;
        double dAmountTotal;
        double dAmountAverage;

    using (StreamReader sr = new StreamReader("Donations.txt"))
    {
        while (sr.Peek() != -1)
        {
            sName = sr.ReadLine();
            Console.WriteLine(sName);

            dAmount = Convert.ToDouble(sr.ReadLine());
            Console.WriteLine(dAmount);
        }

        Console.WriteLine("Press any key to close");
        Console.ReadKey();
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about variables