akia_meyer Ответов: 2

Ошибка Filein и fileout, я не могу этого понять. Пожалуйста, помогите!


Вот мой код:
using System;
using System.IO;
using System.Text.RegularExpressions;
using Util;

namespace Program_9
{
    class Program
    {
        const string INPUT_FILE_NAME = "C:\\Users\\Programing 1\\Soluation 1\\Program 9\\Retirement Numbers\\Input";
        const string OUTPUT_FILE_NAME = "C:\\Users\\Programing 1\\Soluation 1\\Program 9\\Retirement Numbers\\Output";

        static string lineIn;
        static StreamReader fileIn;
        static StreamWriter fileOut;
        static char WType, WElig;
        static uint id;
        static int WAge, WExp;
        static double numOfEmployees;
        static double AvgAge, AvgExp, AgeAvgTotal = 0.0, WAge1Total = 0.0, WAge2Total = 0.0, WAge3Total = 0.0, WAge4Total = 0.0, WAge5Total = 0.0;
        static double WAge6Total = 0.0, WAge7Total = 0.0, WAge8Total = 0.0, WAge9Total = 0.0, WAge10Total = 0.0, WAge11Total = 0.0, WAge12Total = 0.0;
        static double ExpAvgTotal = 0.0, WExp1Total = 0.0, WExp2Total = 0.0, WExp3Total = 0.0, WExp4Total = 0.0, WExp5Total = 0.0;
        static double WExp6Total = 0.0, WExp7Total = 0.0, WExp8Total = 0.0, WExp9Total = 0.0, WExp10Total = 0.0, WExp11Total = 0.0, WExp12Total = 0.0;

        static void Main()
        {
            OpenFiles();
            PrintReportHeadings();
            while ((lineIn=fileIn.ReadLine()) !=null)
            {
                ParseLineIn();
                PrintDetailLine();
                UpdateTotals();
            }
            CalcAvg();
            PrintAvg();
            CloseFiles();
            DspData();
        }

        static void OpenFiles()
        {
            if (File.Exists(INPUT_FILE_NAME))
            {
                fileIn = File.OpenText(INPUT_FILE_NAME);
                Console.WriteLine("{0} was opened", INPUT_FILE_NAME);
            }
            else
            {
                Console.WriteLine("Error: {0} does not exit\n", INPUT_FILE_NAME);
                ConIO.Exit();
            }
            if (File.Exists(OUTPUT_FILE_NAME))
            {
                fileOut = File.CreateText(OUTPUT_FILE_NAME);
                Console.WriteLine("{0} was created\n", OUTPUT_FILE_NAME);
            }
            else
            {
                Console.WriteLine("Error: {0} could not be created\n", OUTPUT_FILE_NAME);
                ConIO.Exit();
            }
        }

        static void PrintReportHeadings()
        {
            fileOut.WriteLine("Employee  Age  Experience  Eligibility");
            fileOut.WriteLine("{0,9},  {1,7},  {2,7}, {3}", id, WAge, WExp, WElig);
            fileOut.WriteLine();
            fileOut.WriteLine("Average {0,7:}, {1,7}", AvgAge, AvgExp);
        }
        static void ParseLineIn(unit id, char WType, double WAge, double WExp, double WElig)
        {
            string[] words = new string[4];

            lineIn = lineIn.Trim();
            while (Regex.IsMatch(lineIn, "[ ]{2}"))
                lineIn = lineIn.Replace("  ", " ");
            words = lineIn.Split(' ');
            id = UInt32.Parse(words[0]);
            WType = Double.Parse(words[1]);
            WAge = Double.Parse(words[2]);
            WExp = Double.Parse(words[3]);
        }

        static void PrintDetailLine()
        {
            fileOut.WriteLine("{0} {1,7:d} {2,7:d} {3,7:d} {4,7:d} {5,3}",
                id, WAge, WExp, WElig);
        }

        static void UpdateTotals()
        {
            numOfEmployees++;
            WAge1Total += WAge1;
            WAge2Total += WAge2;
            WAge3Total += WAge3;
            WAge4Total += WAge4;
            WAge5Total += WAge5;
            WAge6Total += WAge6;
            WAge7Total += WAge7;
            WAge8Total += WAge8;
            WAge9Total += WAge9;
            WAge10Total += WAge10;
            WAge11Total += WAge11;
            WAge12Total += WAge12;
            AgeAvgTotal += AvgAge;
            WExp1Total += WExp1;
            WExp2Total += WExp2;
            WExp3Total += WExp3;
            WExpTotal += WExp4;
            WExp5Total += WExp5;
            WExp6Total += WExp6;
            WExp7Total += WAExp7;
            WExp8Total += WExp8;
            WExp9Total += WExp9;
            WExp10Total += WExp10;
            WExp11Total += WExp11;
            WExp12Total += WExp12;
            ExpAvgTotal += AvgExp;
        }

        static void CalcAvg()
        {
            AvgAge = (WAge1 + WAge2 + WAge3 + WAge4 + WAge5 + WAge6 + WAge7 + WAge8 + WAge9 + WAge10 + WAge11 + WAge12) / numOfEmployees;
        }

        static void CalcAvg()
        {
            AvgAge = AgeAvgTotal / numOfEmployees;
            AvgExp = ExpAvgTotal / numOfEmployees;
        }

        static void PrintAvg()
        {
            fileOut.WriteLine(" ");
            fileOut.WriteLine("Avg {0,7:f} {1,7:f}", AvgAge, AvgExp);
        }

        static void CloseFiles()
        {
            fileIn.Close(); fileOut.Close();
        }

        static void DspData()
        {
            switch (WType)
            {
                case 'W':
                case 'w':
                    if (WAge >= 63 && WExp >= 25)
                        Console.WriteLine("{0} {1} {2} Employee can retire.", id, WAge, WExp);
                    else if (WAge >= 63 && WExp < 25)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to lack of experience.", id, WAge, WExp);
                    else if (WAge < 63 && WExp >= 25)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to being underage.", id, WAge, WExp);
                    else if (WAge < 63 && WExp < 25)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to being underage and lack of experience.", id, WAge, WExp);
                    break;
                case 'S':
                case 's':
                    if (WAge >= 60 && WExp >= 24)
                        Console.WriteLine("{0} {1} {2} Employee can retire.", id, WAge, WExp);
                    else if (WAge >= 60 && WExp < 24)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to lack of experience.", id, WAge, WExp);
                    else if (WAge < 60 && WExp >= 24)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to being underage.", id, WAge, WExp);
                    else if (WAge < 60 && WExp < 24)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to being underage and lack of experience.", id, WAge, WExp);
                    break;
                case 'M':
                case 'm':
                    if (WAge >= 55 && WExp >= 20)
                        Console.WriteLine("{0} {1} {2} Employee can retire.", id, WAge, WExp);
                    else if (WAge >= 55 && WExp < 20)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to lack of experience.", id, WAge, WExp);
                    else if (WAge < 55 && WExp >= 20)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to being underage.", id, WAge, WExp);
                    else if (WAge < 55 && WExp < 20)
                        Console.WriteLine("{0} {1} {2} Employee cannot retire due to being underage and lack of experience.", id, WAge, WExp);
                    break;
            }
        }
    }
}

Вот мой финеин:
1235 Вт 45 20
2536 Вт 55 21
5894 Вт 60 30
4597 Вт 75 35
2597 с 35 10
5689 с 40 20
5489 Вт 55 39
5872 М 60 40
5569 М 55 25
5566 Вт 80 20
8865 м 59 35
5598 с 65 35

Что я уже пробовал:

Кроме всего, что я могу придумать, я не знаю, как это исправить. Я новичок, и мой учитель-сторонник формирования, поэтому все мое форматирование, на которое сейчас похожа программа, Я не могу изменить. Я сделал это в Visual 2015, так что отступы немного сбились.

Это проблема с UpdateTotals() в Main(), статический недействительными UpdateTotals() нормально. Я не могу понять, что я делаю не так. Он просто говорит: "нет никакого аргумента, соответствующего требуемому формальному параметру "WAge1" программы .UpdateTotals()'."

2 Ответов

Рейтинг:
11

akia_meyer

Util-это ссылка, которую предоставил учитель, я не знаю, как ее отправить.
Я закрепил Калавга на

static void CalcAvg()
        {
            AvgAgeTotal = (WAge1 + WAge2 + WAge3 + WAge4 + WAge5 + WAge6 + WAge7 + WAge8 + WAge9 + WAge10 + WAge11 + WAge12);
            AvgAge = AgeAvgTotal / numOfEmployees;
            AvgExp = ExpAvgTotal / numOfEmployees;
        }


Я перестроил программу, я скопирую ошибки.
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS7036	There is no argument given that corresponds to the required formal parameter 'WAge1' of 'Program.UpdateTotals(int, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)'	Program9.1	C:\Users\Programing 1\Soluation 1\Program 9\Program9.1\Program9.1\Program.cs	37	Active
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS7036	There is no argument given that corresponds to the required formal parameter 'WAge1' of 'Program.CalcAvg(int, double, double, double, double, double, double, double, double, double, double, double)'	Program9.1	C:\Users\Programing 1\Soluation 1\Program 9\Program9.1\Program9.1\Program.cs	39	Active
Severity	Code	Description	Project	File	Line	Suppression State
Warning	CS0649	Field 'Program.WElig' is never assigned to, and will always have its default value	Program9.1	C:\Users\Programing 1\Soluation 1\Program 9\Program9.1\Program9.1\Program.cs	20	Active

Жаль, что я не могу опубликовать снимок экрана...это поможет.


Рейтинг:
1

OriginalGriff

Если я вставлю ваш код в новый проект и попытаюсь его скомпилировать, то получу гораздо больше ошибок, чем вы говорите:

Error	1	Type 'Program_9.Program' already defines a member called 'CalcAvg' with the same parameter types	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	143	21	GeneralTestingConsole
Error	2	The type or namespace name 'Util' could not be found (are you missing a using directive or an assembly reference?)	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	19	7	GeneralTestingConsole
Error	3	No overload for method 'ParseLineIn' takes 0 arguments	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	46	17	GeneralTestingConsole
Error	4	The call is ambiguous between the following methods or properties: 'Program_9.Program.CalcAvg()' and 'Program_9.Program.CalcAvg()'	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	50	13	GeneralTestingConsole
Error	5	The name 'ConIO' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	66	17	GeneralTestingConsole
Error	6	The name 'ConIO' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	76	17	GeneralTestingConsole
Error	7	The type or namespace name 'unit' could not be found (are you missing a using directive or an assembly reference?)	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	87	33	GeneralTestingConsole
Error	8	Cannot implicitly convert type 'double' to 'char'. An explicit conversion exists (are you missing a cast?)	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	96	21	GeneralTestingConsole
Error	9	The name 'WAge1' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	110	27	GeneralTestingConsole
Error	10	The name 'WAge2' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	111	27	GeneralTestingConsole
Error	11	The name 'WAge3' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	112	27	GeneralTestingConsole
Error	12	The name 'WAge4' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	113	27	GeneralTestingConsole
Error	13	The name 'WAge5' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	114	27	GeneralTestingConsole
Error	14	The name 'WAge6' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	115	27	GeneralTestingConsole
Error	15	The name 'WAge7' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	116	27	GeneralTestingConsole
Error	16	The name 'WAge8' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	117	27	GeneralTestingConsole
Error	17	The name 'WAge9' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	118	27	GeneralTestingConsole
Error	18	The name 'WAge10' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	119	28	GeneralTestingConsole
Error	19	The name 'WAge11' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	120	28	GeneralTestingConsole
Error	20	The name 'WAge12' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	121	28	GeneralTestingConsole
Error	21	The name 'WExp1' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	123	27	GeneralTestingConsole
Error	22	The name 'WExp2' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	124	27	GeneralTestingConsole
Error	23	The name 'WExp3' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	125	27	GeneralTestingConsole
Error	24	The name 'WExpTotal' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	126	13	GeneralTestingConsole
Error	25	The name 'WExp4' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	126	26	GeneralTestingConsole
Error	26	The name 'WExp5' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	127	27	GeneralTestingConsole
Error	27	The name 'WExp6' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	128	27	GeneralTestingConsole
Error	28	The name 'WAExp7' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	129	27	GeneralTestingConsole
Error	29	The name 'WExp8' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	130	27	GeneralTestingConsole
Error	30	The name 'WExp9' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	131	27	GeneralTestingConsole
Error	31	The name 'WExp10' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	132	28	GeneralTestingConsole
Error	32	The name 'WExp11' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	133	28	GeneralTestingConsole
Error	33	The name 'WExp12' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	134	28	GeneralTestingConsole
Error	34	The name 'WAge1' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	23	GeneralTestingConsole
Error	35	The name 'WAge2' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	31	GeneralTestingConsole
Error	36	The name 'WAge3' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	39	GeneralTestingConsole
Error	37	The name 'WAge4' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	47	GeneralTestingConsole
Error	38	The name 'WAge5' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	55	GeneralTestingConsole
Error	39	The name 'WAge6' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	63	GeneralTestingConsole
Error	40	The name 'WAge7' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	71	GeneralTestingConsole
Error	41	The name 'WAge8' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	79	GeneralTestingConsole
Error	42	The name 'WAge9' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	87	GeneralTestingConsole
Error	43	The name 'WAge10' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	95	GeneralTestingConsole
Error	44	The name 'WAge11' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	104	GeneralTestingConsole
Error	45	The name 'WAge12' does not exist in the current context	D:\Documents\AA Backed Up\My Projects\GeneralTesting\GeneralTestingConsole\Program.cs	140	113	GeneralTestingConsole

И ни один из них не упоминает UpdateTotals.
Так что либо этот код совсем не похож на тот, с которым вы пытаетесь работать, либо вы давно не компилировались и просматриваете старые сообщения об ошибках.

В этом коде у вас есть два разных метода, называемых CalcAvg, которые имеют идентичные сигнатуры (то есть они принимают одни и те же параметры - нет), что означает, что система не может сказать, какой из них она должна вызвать.

Перестройте свой проект (используйте CTRL+SHIFT+B), и вы получите те же ошибки, что и я. Начните с верхней части списка и попробуйте исправить их - удалите один из методов CalcAvg, затем передайте параметры ParseLineIn и так далее.