Getting some errors at least this time I know why..seems like I am not declaring the methods inside my classes I tried rearranging the method and then inserting all my code into a class but Im still getting all those errors in the bottom.

If you guys can tell me how to also avoid this problem in the future that would be great!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem8Pg179
{
    public class GranolaSales
    {
        public static void Main()
        {
            const int NUMBER_OF_BARS = 12;
            const double NUMBER_OF_CASES = 5;
            const double ASSOCIATION_FEES = 0.10;
            
            string inputValue;
            int cases,
                bars;

            DisplayInstructions();
            
            cases = GetCases("cases");
            bars = GetBarPrice("bars");
            

            DisplayResults();

            Console.ReadKey();
        }

    //    public static void DisplayInstructions();
    //    {
    //    Console.WriteLine("This program will calculate granola sales");
    //    Console.WriteLine("Please enter the number of cases sold and price per bar.");
    //    Console.WriteLine("Please enter in the following values...");
    //    }  

    //   public static int GetBars(int bars)
    //   {
    //        Console.WriteLine("Please enter number of {0} sold: ");
    //        inValue = Console.ReadLine();
    //        someintValue = int.Parse(inValue);
    //        return someIntValue;
    //        Console.Clear();           
    //   }
      
    //public static int GetPrice(int price)
    //   {
    //        Console.WriteLine("Please enter the price per {0}: ");
    //        inValue = Console.ReadLine();
    //        someintValue = int.Parse(inValue);
    //        return someIntValue;
    //        Console.Clear();       
    //   }

    //public static int CalculateSales(int bars, int cases)
    //{
    // return bars * price;
    //}
      
    //public static int CalculateProceeds(int ASSOCIATION_FEES, int bars, int cases)
    //{
    //return ASSOCIATION_FEES * (bars * cases);
    //}

    
    //public static double DisplayResults(int bars, int cases, int ASSOCIATION_FEES);
    //{
    //Console.WriteLine("Club Proceeds: {0:C2}" 
    //                  , CalculateProceeds)); 
    ////inputValue = Console.ReadLine();
    ////someintValue = int.Parse(inputValue);
    ////return someIntValue;
    ////Console.Clear()
    }

      
         
}
         public static void DisplayInstructions();
        {
        Console.WriteLine("This program will calculate granola sales");
        Console.WriteLine("Please enter the number of cases sold and price per bar.");
        Console.WriteLine("Please enter in the following values...");
        }  

       public static int GetBarPrice(int barPrice)
       {
            Console.WriteLine("Please enter the {0} of each bar: ");
            inValue = Console.ReadLine();
            someintValue = int.Parse(inValue);
            return someIntValue;
            Console.Clear();           
       }
      
    public static int GetCases(int price)
       {
            Console.WriteLine("Please enter the number of {0} sold: ");
            inValue = Console.ReadLine();
            someintValue = int.Parse(inValue);
            return someIntValue;
            Console.Clear();       
       }

    public static int CalculateSales(int bars, int cases)
    {
     return bars * cases;
    }
      
    public static int CalculateProceeds(int ASSOCIATION_FEES, int bars, int cases)
    {
    return ASSOCIATION_FEES * (bars * cases);
    }

    
    public static double DisplayResults(int bars, int cases, int ASSOCIATION_FEES);
    {
    Console.WriteLine("Club Proceeds: {0:C2}" 
                      , CalculateProceeds)); 
    //inputValue = Console.ReadLine();
    //someintValue = int.Parse(inputValue);
    //return someIntValue;
    //Console.Clear()
}

The name 'GetCases' does not exist in the current context 22 21
The name 'GetBarPrice' does not exist in the current context 23 20
The name 'DisplayResults' does not exist in the current context 26 13
The name 'DisplayInstructions' does not exist in the current context 20 13
Expected class, delegate, enum, interface, or struct 80 24
Expected class, delegate, enum, interface, or struct 87 22
Expected class, delegate, enum, interface, or struct 96 19
Expected class, delegate, enum, interface, or struct 105 19
Expected class, delegate, enum, interface, or struct 110 19
Expected class, delegate, enum, interface, or struct 116 19

Thanks Again!

Recommended Answers

All 12 Replies

Line 75 ends your class, and line 79 ends the namespace. Move those methods to before line 75.

I still had the same errors when the methods were before the class but i will try again

You have semi colons on the lines where you are declaring a method
example on line 80 you have public static void DisplayInstructions(); followed by braces. Remove those semi colons and place your methods into the class

You have code outside class and ... quite a few other errors

using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    namespace Problem8Pg179
    {
        public class GranolaSales
        {
            public static void Main()
            {
            const int NUMBER_OF_BARS = 12;
            const double NUMBER_OF_CASES = 5;
            const double ASSOCIATION_FEES = 0.10;
     
            string inputValue;
        int cases, bars;
     
        DisplayInstructions();

            cases = GetCases(1); // OMG! GetCases(int price), "cases" is a string not an integer
            bars = GetBarPrice(1); // and same here


            //DisplayResults(); // WHERE ARE PARAMETERS FOR DisplayResults(int bars, int cases, int ASSOCIATION_FEES) ???
     
            Console.ReadKey();
            } // void Main

            public static void DisplayInstructions() // ; <- Semicolon in the wrong place
        {
        Console.WriteLine("This program will calculate granola sales");
        Console.WriteLine("Please enter the number of cases sold and price per bar.");
        Console.WriteLine("Please enter in the following values...");
        }
     
    public static int GetBarPrice(int barPrice)
    {
        string inValue; // DECLARE VARIABLES!!!
        int someintValue; // DECLARE VARIABLES!!!

    Console.WriteLine("Please enter the {0} of each bar: ");
    inValue = Console.ReadLine();
    someintValue = int.Parse(inValue);
    // return someIntValue; // C# is CASESENSITIVE SO someIntValue IS NOT THE SAME AS someintValue
    return someintValue;
    Console.Clear(); // <- How do you get in to this line after returning from this function in the previous line ???!!!
    }
     
    public static int GetCases(int price)
    {
        string inValue; // DECLARE VARIABLES!!!
        int someintValue; // DECLARE VARIABLES!!!

        Console.WriteLine("Please enter the number of {0} sold: ");
        inValue = Console.ReadLine();
        someintValue = int.Parse(inValue);
        // return someIntValue; // C# is CASESENSITIVE SO someIntValue IS NOT THE SAME AS someintValue
        return someintValue;
        Console.Clear(); // <- How do you get in to this line after returning from this function in the previous line ???!!!
    }
     
    public static int CalculateSales(int bars, int cases)
    {
    return bars * cases;
    }
     
    public static int CalculateProceeds(int ASSOCIATION_FEES, int bars, int cases)
    {
    return ASSOCIATION_FEES * (bars * cases);
    }
     
     
    public static double DisplayResults(int bars, int cases, int ASSOCIATION_FEES) // ; <- Semicolon in the wrong place
    {
        //Console.WriteLine("Club Proceeds: {0:C2}", CalculateProceeds);  // ) <- removed extra 
        // CalculateProceeds NEEDS ARGUMENTS CalculateProceeds(int ASSOCIATION_FEES, int bars, int cases) WHERE ARE THEY???

        return 0; // <- REMOVE THIS, I used it just to avoid error msg

    //inputValue = Console.ReadLine();
    //someintValue = int.Parse(inputValue);
    //return someIntValue;
    //Console.Clear()
    }
     
        } // class GranolaSales
    } // namespace Problem8Pg179

tell me how to also avoid this problem in the future that would be great!

Turn on every error msg, editor helps etc. You should see when things start to go wrong straight away, not after writing a few pages of piece of... code. And if you get an error of missing/extra thing, correct the error straight away. Do not wait until you have 100 errors and then start to wonder how to fix 'em.
If the brackets are far away, add a comment to the ending bracket which tells what is that bracket closing. See above how I commented the ending of the class code and the namespace.
Finally write your code with a good editor, like Microsoft's free Visual C# Express. Notepad is a fine editor but it's not for you ;)

HTH

HTH

Ok with the help of all of you I cut and trimmed down the problems a bit more...I know have 15 errors left and this is what the code looks like. I even moved my methods inside the class and denoted where the class ends and where does the namespace end .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProblemGranola
{
    class GranolaSales
    {
        static void Main()
        {
            const int NUMBER_OF_BARS = 12;
            const double NUMBER_OF_CASES = 5;
            const double ASSOCIATION_FEES = 0.10;
            
            string inputValue;
            int cases,
                bars;

            DisplayInstructions();
            
            cases = GetCases(1);
            bars = GetBarPrice(1);
            

            DisplayResults(int bars, int cases, int ASSOCIATION_FEES)

            Console.ReadKey();
        }

     public static void DisplayInstructions()
        {
        Console.WriteLine("This program will calculate granola sales");
        Console.WriteLine("Please enter the number of cases sold and price per bar.");
        Console.WriteLine("Please enter in the following values...");
        }  

       public static int GetBarPrice(int barPrice)
       {
            Console.WriteLine("Please enter the {0} of each bar: ");
            inValue = Console.ReadLine();
            someIntValue = int.Parse(inValue);
            return someIntValue;
            Console.Clear();           
       }
      
    public static int GetCases(int price)
       {
            Console.WriteLine("Please enter the number of {0} sold: ");
            inValue = Console.ReadLine();
            someintValue = int.Parse(inValue);
            return someIntValue;
            //Console.Clear();       
       }

    public static int CalculateSales(int bars, int cases)
    {
     return bars * cases;
    }
      
    public static int CalculateProceeds(int ASSOCIATION_FEES, int bars, int cases)
    {
    return ASSOCIATION_FEES * (bars * cases);
    }

    
    public static double DisplayResults(int bars, int cases, int ASSOCIATION_FEES)
    {
    Console.WriteLine("Club Proceeds: {0:C2}" 
                      , CalculateProceeds)); 
    } // class ends

You are missing 2 closing curly braces at the end. One should close the class, the other should close the namespace.

You are missing 2 closing curly braces at the end. One should close the class, the other should close the name-space.

sorry i didn't copy the entire code I have the bracket where class ends and also the closing bracket for name-space. But I still have errors

Please list the errors.

Please list the errors.

ok i fixed all the errors my only problem is the "Debug" option is greyed out , and so is the "green arrow" . What is going on?

here is my revised code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem8Pg179
{
    public class GranolaSales
    {
        public static void Main()
        {
            const int NUMBER_OF_BARS = 12;
            const double NUMBER_OF_CASES = 5;
            const double ASSOCIATION_FEES = 0.10;
            
            string inputValue;
            string cases,
                bars;

            DisplayInstructions();
            
            cases = GetCases("cases");
            bars = GetBarPrice("bars");
            

            DisplayResults();

            Console.ReadKey();
        }

     public static void DisplayInstructions()
     {
        Console.WriteLine("This program will calculate granola sales");
        Console.WriteLine("Please enter the number of cases sold and price per bar.");
        Console.WriteLine("Please enter in the following values...");
     }   

       public static int GetBarPrice(int barPrice)
       {
            Console.WriteLine("Please enter the {0} of each bar: ");
            inValue = Console.ReadLine();
            someintValue = int.Parse(inValue);
            return someIntValue;
            Console.Clear();           
       }
      
    public static int GetCases(int price)
       {
            Console.WriteLine("Please enter the number of {0} sold: ");
            inValue = Console.ReadLine();
            someintValue = int.Parse(inValue);
            return someIntValue;
            Console.Clear();       
       }

    public static int CalculateSales(int bars, int cases)
    {
     return bars * cases;
    }
      
    public static int CalculateProceeds(int ASSOCIATION_FEES, int bars, int cases)
    {
    return ASSOCIATION_FEES * (bars * cases);
    }


    public static double DisplayResults(int bars, int cases, int ASSOCIATION_FEES)
    {
        Console.WriteLine("Club Proceeds: {0:C2}"
                          , CalculateProceeds);
    }
    } // class ends 

      
         
} // namespace ends

ok i opened up a new project window and repasted the same code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem8Pg179
{
    public class GranolaSales
    {
        public static void Main()
        {
            const int NUMBER_OF_BARS = 12;
            const double NUMBER_OF_CASES = 5;
            const double ASSOCIATION_FEES = 0.10;

            string inputValue;
            string cases,
                bars;

            DisplayInstructions();

            cases = GetCases("cases");
            bars = GetBarPrice("bars");


            DisplayResults();

            Console.ReadKey();
        }

        public static void DisplayInstructions()
        {
            Console.WriteLine("This program will calculate granola sales");
            Console.WriteLine("Please enter the number of cases sold and price per bar.");
            Console.WriteLine("Please enter in the following values...");
        }

        public static int GetBarPrice(int barPrice)
        {
            Console.WriteLine("Please enter the {0} of each bar: ");
            inValue = Console.ReadLine();
            someIntValue = int.Parse(inValue);
            return someIntValue;
            Console.Clear();
        }

        public static int GetCases(int price)
        {
            Console.WriteLine("Please enter the number of {0} sold: ");
            inValue = Console.ReadLine();
            someIntValue = int.Parse(inValue);
            return someIntValue;
            Console.Clear();
        }

        public static int CalculateSales(int bars, int cases)
        {
            return bars * cases;
        }

        public static int CalculateProceeds(int ASSOCIATION_FEES, int bars, int cases)
        {
            return ASSOCIATION_FEES * (bars * cases);
        }


        public static double DisplayResults(int bars, int cases, int ASSOCIATION_FEES)
        {
            Console.WriteLine("Club Proceeds: {0:C2}"
                              , CalculateProceeds);
        }
    } // class ends 



} // namespace ends

I regained 16 of the errors :( here are errors :

Error 7 The name 'someIntValue' does not exist in the current context 42 13
Error 9 The name 'someIntValue' does not exist in the current context 43 20
Error 11 The name 'someIntValue' does not exist in the current context 51 13
Error 13 The name 'someIntValue' does not exist in the current context 52 20
Error 6 The name 'inValue' does not exist in the current context 41 13
Error 8 The name 'inValue' does not exist in the current context 42 38
Error 10 The name 'inValue' does not exist in the current context 50 13
Error 12 The name 'inValue' does not exist in the current context 51 38
Error 14 The best overloaded method match for 'System.Console.WriteLine(string, params object[])' has some invalid arguments 69 13
Error 1 The best overloaded method match for 'Problem8Pg179.GranolaSales.GetCases(int)' has some invalid arguments 22 21
Error 3 The best overloaded method match for 'Problem8Pg179.GranolaSales.GetBarPrice(int)' has some invalid arguments 23 20
Error 5 No overload for method 'DisplayResults' takes 0 arguments 26 13
Error 15 Argument 2: cannot convert from 'method group' to 'object[]' 70 33
Error 2 Argument 1: cannot convert from 'string' to 'int' 22 30
Error 4 Argument 1: cannot convert from 'string' to 'int' 23 32

my only problem is the "Debug" option is greyed out , and so is the "green arrow"

Check Build\Configuration Manager. Configuration should be Debug, not Release.

ok i opened up a new project window and repasted the same code:

... and the same errors too ;)

I regained 16 of the errors here are errors :

Very clear error messages. Like "Error 4 Argument 1: cannot convert from 'string' to 'int' 23 32 ", just fix it. BTW, I had fixed these errors in the previous page.

someIntValue and inValue has not been declared, if u want it in multiple methods, put that as a global variable or pass it in a method as an argument.

GetCases() and GetBarPrice() expects an integer as the argument, u are passing a string.

all these are simple issues, or may be the very basics of errors you can say. just go through what you have written, you will find the solution in the errors itself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.