1

IT WORKS NOW! After reading what everyone had to say I started playing with it some more and reading tips from the site.

*For anyone reading in the future. I was missing some brackets as mentioned in the answers below which I added. I also made the mistake of not checking my if statements. I have it so below where the states have to equal "AL", etc. Which isn't possible, because those are divisions.

Thank you to anyone who can help, formatting is a weak point of mine. All this code needs to do is display all of the info from the arrays for teams in the AL and NL division, along with two columns not in array format. One being a variable showing (wins/total), the other column showing the difference between (run score and run against).

But, I keep getting an error about the input string being wrong. I am a bit unsure on what exactly is wrong.

My first guess is that perhaps, because I don't have the last two columns in array format that this is causing the error. But, I'm not sure if I can just put them in an empty array.

Or, perhaps because when I called the two modules I repeated two of the array names. I did this, because I saw my teacher had done it in an example he showed us in class. However, it doesn't seem to be working this time.

I tried to give as much info as I could without text bombing, I can give any other info if needed.

Woot! Thanks to the info, the error is gone! Sadly, I can't seem to get any of the information from the arrays to show up in columns.

        string[] teams = { "Boston Red Sox", "New York Yankees", "Tampa Bay Rays", "Toronto Blue Jays", "Baltimore Orioles",
            "Cleveland Indians", "Minnesota Twins", "Kansas City Royals", "Chicago White Sox", "Detroit Tigers", "Houston Astros", "Los Angeles Angels",
            "Seattle Mariners", "Texas Rangers", "Oakland Athletics", "Washington Nationals", "Miami Marlins", "Atlanta Braves", "New York Mets", "Philadelphia Phillies",
            "Chicago Cubs", "Milwaukee Brewers", "St. Louis Cardinals", "Pittsburgh Pirates", "Cincinnati Reds", "Los Angeles Dodgers", "Arizona Diamondbacks",
            "Colorado Rockies", "San Diego Padres", "San Francisco Giants" };

        string[] state = { "MA", "NY", "FL", "CN", "MD", "OH", "MN", "MO", "IL", "MI", "TX", "CA", "WA", "TX", "CA", "DC",
            "FL", "GA", "NY", "PA", "IL", "WI", "MO", "PA", "OH", "CA", "AZ", "CO", "CA", "CA" };

        string[] clinch = { "x", "y", "n", "n", "n", "*", "y", "n", "n", "n", "x", "n", "n", "n", "n", "x", "n", "n",
            "n", "n", "x", "n", "n", "n", "n", "*", "y", "y", "n", "n" };

        string[] divison = { "ALE", "ALE", "ALE", "ALE", "ALE", "ALC", "ALC", "ALC", "ALC", "ALC", "ALW", "ALW", "ALW", "ALW", "ALW", "NLE", "NLE", "NLE", "NLE", "NLE", "NLC", "NLC", "NLC",
            "NLC", "NLC", "NLW", "NLW", "NLW", "NLW", "NLW" };

        int[] wins = { 93, 91, 80, 76, 75, 102, 85, 80, 67, 64, 101, 80, 78, 78, 75, 97, 77, 72, 70, 66, 92, 86, 83, 75, 68, 104, 93, 87, 71, 64 };

        int[] losses = { 69, 71, 82, 86, 87, 60, 77, 82, 95, 98, 61, 82, 84, 84, 87, 65, 85, 90, 92, 96, 70, 76, 79, 87, 94, 58, 69, 75, 91, 98 };

        int[] runsScored = { 785, 858, 694, 693, 743, 818, 815, 702, 706, 735, 896, 710, 750, 799, 739, 819, 778, 732, 735, 690, 822, 732, 761, 668, 753, 770, 812, 824, 604, 639 };

        int[] runsAgainst = { 668, 660, 704, 784, 841, 564, 788, 791, 820, 894, 700, 709, 772, 816, 826, 672, 822, 821, 863, 782, 695, 697, 705, 731, 869, 580, 659, 757, 816, 776 };


        divNL(teams, state, clinch, divison, wins, losses, runsScored, runsAgainst, wins, losses);
        divAL(teams, state, clinch, divison, wins, losses, runsScored, runsAgainst, losses, runsScored);

    }

    static void divNL(string[] t, string[] state, string[] c, string[] d, int[] w, int[] l, int[] r, int[] s, int[] p, int[] o)
    {
        // displays all info for NL division
        string stateM = "";
        double pctWins = 0.0;
        double raRS = 0.0;
        int win = 0, loss = 0;
        int aR = 0, sR = 0;
        pctWins = (double)win / (win + loss);
        raRS = (double)aR - sR;


        Console.WriteLine("All Data for NL Division Teams");

        Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "Team", "State", "Clinch", "Div", "W", "L", "RS", "RA", "WinPCT", "RA/RS");
        Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----", "----", "-----", "----", "-----", "----", "-----", "-----");

        for (int i = 0; i < state.Length; ++i)
        {
            if (state[i] == "NLC" | state[i] == "NLW" | state[i] == "NLE")

            {
                stateM = state[i];
                Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
                    w[i], l[i], r[i], s[i], pctWins, raRS);
            }
        }

    }

    static void divAL(string[] t, string[] state, string[] c, string[] d, int[] w, int[] l, int[] r, int[] s, int[] p, int[] o)
    {
        //displays all info for Al divsion
        string stateM = "";
        double pctWins = 0.0;
        double raRS = 0.0;
        int win = 0, loss = 0;
        int aR = 0, sR = 0;
        pctWins = (double)win / (win + loss);
        raRS = (double)aR - sR;


        Console.WriteLine("\n\nAll Data for AL Division Teams\n");

        Console.WriteLine("{0,20}{1,8}{2,8}{3,8}{4,8}{5,8}{6,8}{7,8}{8,8}{9,8}", "Team", "State", "Clinch", "Div", "W", "L", "RS", "RA", "WinPCT", "RA/RS");
        Console.WriteLine("{0,20}{1,8}{2,8}{3,8}{4,8}{5,8}{6,8}{7,8}{8,8}{9,8}", "----", "-----", "----", "----", "-----", "----", "-----", "----", "-----", "-----");

        for (int i = 0; i < state.Length; ++i)
        {
            if (state[i] == "ALC" | state[i] == "ALE" | state[i] == "ALE")

            {
                stateM = state[i];
                Console.WriteLine("{0,8}{1,8}{2,8}{3,8}{4,8}{5,8}{6,8}{7,8}{8,8}{9,8}", t[i], state[i], c[i], d[i],
                    w[i], l[i], r[i], s[i], pctWins, raRS);
            }
        }

    }
M00
  • 13
  • 4
  • 2
    Why not strip your example code down to what really matters to illustrate the erroneous behaviour? – Uwe Keim Nov 06 '17 at 06:53
  • 1
    `Console.WriteLine("0,24}` seems to miss a `{`? – Uwe Keim Nov 06 '17 at 06:54
  • Opps, sorry if it is too long. I'm a bit unsure of what to take away because I am not sure what is causing the problem. – M00 Nov 06 '17 at 06:57
  • Call stack FTW! – Uwe Keim Nov 06 '17 at 06:57
  • I'm sorry, I don't know what that means, but thanks for pointing out that {. I will see if that is causing the problems – M00 Nov 06 '17 at 06:58
  • 2
    "I am not sure what is causing the problem" - that's where you should *try* taking aspects away until you don't get the problem any more. Or start form a new project and gradually *add* bits. Or use the debugger. There are lots of ways of reducing the scope of a problem, and it's a **vital** skill to learn. – Jon Skeet Nov 06 '17 at 07:12
  • 2
    Additionally, you haven't indicated *where* you get the exception - which line is throwing. That's always useful information - initially to you when trying to work out what's wrong, but also to us when we're trying to help you. – Jon Skeet Nov 06 '17 at 07:13
  • Sorry, this is a bit new to me. My teacher hasn't been explaining in much detail, so some things go over my head. Honestly, I wasn't aware the code would tell you were something was thrown. I will have to look out for that from now on. – M00 Nov 06 '17 at 07:24
  • 2
    I would definitely put some time into learning diagnostic skills before going any further - in particular, looking at stack traces and learning to use a debugger. If I were teaching programming, I'd definitely teach the basics of diagnostics before going as far as it looks like you have :( Maybe ask your teacher to give a lesson to the whole class on it? – Jon Skeet Nov 06 '17 at 07:33
  • Thank you! lol it is nice having some sort of goal instead of winging it. I can promise whoever is reader this we have never learned about call stack and all these other things. My teacher feels looking things online as you need them is the "way of the future." I'm glad I have this site. – M00 Nov 06 '17 at 07:58

1 Answers1

1

You have forgotten some opening curly braces in these lines:

    Console.WriteLine("0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----",
        "----", "-----", "----", "-----", "----", "-----", "-----");

            Console.WriteLine("0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
                w[i], l[i], r[i], s[i], pctWins, raRS);


    Console.WriteLine("0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----",
        "----", "-----", "----", "-----", "----", "-----", "-----");

            Console.WriteLine("0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
                w[i], l[i], r[i], s[i], pctWins, raRS);

They should be as follow:

    Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----",
        "----", "-----", "----", "-----", "----", "-----", "-----");

            Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
                w[i], l[i], r[i], s[i], pctWins, raRS);


    Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----",
        "----", "-----", "----", "-----", "----", "-----", "-----");

            Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
                w[i], l[i], r[i], s[i], pctWins, raRS);

Hint: Use $"" string format that causes less errors.

Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126
  • Woot! Thank you both. Adding those seemed to get rid of the error. – M00 Nov 06 '17 at 07:06
  • I wish my teacher explained why we use certain things. No one in my class could tell you what this {0,20} numbers mean. Or, what the $"" is for, or does. – M00 Nov 06 '17 at 07:07
  • See these for more info: https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx and https://stackoverflow.com/questions/31014869/what-does-mean-before-a-string – Afshar Mohebi Nov 06 '17 at 07:15