Click here to Skip to main content
14,208,761 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Here is my code:
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;
            }
        }
    }
}

Here is my fineIn:
1235 W 45 20
2536 W 55 21
5894 W 60 30
4597 W 75 35
2597 S 35 10
5689 S 40 20
5489 W 55 39
5872 M 60 40
5569 M 55 25
5566 W 80 20
8865 M 59 35
5598 S 65 35

What I have tried:

Besides everything I can think of, I'm not sure how to fix this. I am a beginner, and my teacher is a stickler for formation so all of my formatting that the program looks like now, I can't change it. I made it in Visual 2015 so the indenting is off a bit.

It is having a problem with the UpdateTotals() in Main(), the static void UpdateTotals() is fine. I can't figure out what I am doing wrong. It just says "There is no argument given that corresponds to the required formal parameter 'WAge1' of 'Program.UpdateTotals()'."
Posted
Updated 30-Nov-16 6:26am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If I paste your code into a new project and try to compile it, I get a lot more errors than you say:
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

And none of them mentions UpdateTotals.
So either that code is nothing like the code you are trying to work with, or you haven't compiled in a long time and are looking at old error messages.

In that code, you have two different methods called CalcAvg which have identical signatures (i.e. they take the same parameters - none) which means the system scan't tell which it should call.

Rebuild your project (use CTRL+SHIFT+B) and you should get the same errors I do. Start from the top of the list, and try to fix them - remove one of the CalcAvg methods, then pass the parameters to ParseLineIn, and so forth.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

The Util is a reference that the teacher provided, I am not sure how to send that.
I fixed CalAvg to
static void CalcAvg()
        {
            AvgAgeTotal = (WAge1 + WAge2 + WAge3 + WAge4 + WAge5 + WAge6 + WAge7 + WAge8 + WAge9 + WAge10 + WAge11 + WAge12);
            AvgAge = AgeAvgTotal / numOfEmployees;
            AvgExp = ExpAvgTotal / numOfEmployees;
        }


I rebuilt the program, I will copy the errors over.
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

I wish that I could post a screen shot...that would help.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190612.1 | Last Updated 30 Nov 2016
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100