Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am having a problem with this program that I am trying to write. I first wrote the program within the main. Then I attempted to divide the program into separate functions. The more specific problem that I am having occurs right at the beginning of the first function. The first curly brace prompts me with this Error: Invalid Token '{' in class, struct, or interface member deceleration. Any help with this would be greatly appreciated.


C#
namespace VS_Console_Sand_Box_2
{
    class Program
    {
        static void Main(string[] args)
        {
            //declare variables
            string endLoop;
            int totalScore = 0, avgScore = 0, i = 0, count = 0;
            string[] names = new string[100];
            int[] scores = new int[100];

            //Jumpt to module 1
            InPutData(names, scores, ref count);

            //Jump to module 2
            DisplayPlayerData(names, scores, ref count);

            //jump to module 3
            CalculateAverageScore(scores, totalScore, count, ref avgScore);

            //jump to module 4
            DisplayBelowAverage(names, scores, avgScore, count);


            Console.ReadLine();
        }

        //module 1 get user input
        public static void InPutData(string[] names, int[] scores, ref int count);
        { // <-- Problem starts here...            
             do
                {
                    for (i = 0; i < 100; ++i)
                    {
                        Console.Write("Enter Player Name (Q to quit): ");
                        names[i] = Convert.ToString(Console.ReadLine());

                        if (names[i] == "Q")
                        {
                            break;
                        }

                        Console.Write("Enter Score for {0}: ", names[i]);
                        scores[i] = Convert.ToInt16(Console.ReadLine());
                        count++;
                    }
                }
                while (names[i] != "Q");

    }

        //module 2 display the player name and score
        public static void DisplayPlayerData(string[] names, int[] scores, ref int count);
{
        Console.WriteLine("\n\nName:\t\tScore:");
        for (i = 0; i < count; i++)
        Console.WriteLine("" + names[i] + "\t\t" + scores[i]);
}

        //module 3 calculate the average of all scores
        public static void CalculateAverageScore(int[] scores, int totalScore, int count, ref int avgScore);
{
        foreach (int score in scores)
        totalScore = (totalScore + score);
        avgScore = (totalScore / count);
}

        //module 4 determine and display how many players are below average
        public static void DisplayBelowAverage(string[] names, int[] scores, int avgScore, int count);
{
        Console.WriteLine("\nAverage Score: {0:F2}", avgScore);
        Console.WriteLine("Players who scored below average:\n");

          for (i = 0; i < count; i++)
              if (scores[i] < avgScore)
              {
                    Console.WriteLine("" + names[i] + "\t\t" + scores[i]);
              }
}

    }
}
Posted
Updated 27-Nov-14 6:09am
v3

Quote:
public static void InPutData(string[] names, int[] scores, ref int count);

Remove the semicolon at the end of the line.
 
Share this answer
 
Comments
Member 11136294 27-Nov-14 11:32am    
I cannot believe I did that. Thanks
CPallini 27-Nov-14 13:12pm    
It happens: it happened to me too. :-O
You are welcome.
That is because you're using a line terminator (someone tell me the real name of this character) there ; in your code, that is why the compiler was not expecting the { token in the code and gave this error.

See in your code,

C#
public static void InPutData(string[] names, int[] scores, ref int count); // <--
{


Remove it, and it will be like this now,

C#
public static void InPutData(string[] names, int[] scores, ref int count)
{


.. now it won't complain. :-)

Also, there was no error passing array after all and there won't be an error.
 
Share this answer
 
v2
Comments
Member 11136294 27-Nov-14 11:32am    
I cannot believe I did that. Thanks

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900