-1

A guy in my class made a program to determine the difference between 2 numbers. The way he did it was really ineffective and I told him that. He didn't believe me and wanted me to write better code. I wrote all of the code I need in Visual Studio but every time I try to run the code I get the error message

CS5001: does not contain a static 'main' method suitable for an entry point

I have been looking in the internet for solutions for quite a long time now and I tried a lot out but none of it has worked. I code in C#. I will be really thankful if anyone here can help me. this is my code:


namespace Determine_difference
{
    public class Program
    {

        public static void Main()
        {

        }



         int a, b, c, d; 
       public  void Start() 
        {
            a = 0; 
            b = 1; //this is the difference between the numbers
            c = 1; //c is used to determine how big or small the searched number is. This is kind of unnecessary but I was tired when i wrote this
            d = 1; //d is used so that the console doesn't get spammed with the answers
        }

         public void Update() 
        {
            if (a < b) //this next part only gets executed when the searched number is larger than 0
            {
                if(b-c > a) //the next part then only gets triggered if the searched number minus c are larger than 0
                {
                    c += 1; //c gets 1 higher
                }

                else if(b-c==a) //if the searched number minus c are equal to 0 this part gets executed
                {
                    if (d == 1) // then this part gets executed if d is equal to 1, this is so that the console only prints once
                    {
                        Console.Write("+"); //the console writes "+"
                        Console.Write(c); //and the searched number
                        d = 0; //d is now equal to 0 so that this part of the code doesn't get triggered again
                    }

                }
            }
            if (a > b)
            {
                if (b - c < a)
                {
                    c += 1;
                }

                else if (b + c == a)
                {
                    if (d == 1)
                    {
                        Console.Write("+-c");
                        Console.Write(c);
                        d = 0;
                    }

                }
            }
            if (a == b)
            {
                if (d == 0)
                {
                    Console.WriteLine("+/ -0");
                    d = 0;
                }
            }
        }
    }
}
rioV8
  • 24,506
  • 3
  • 32
  • 49
Diavolo
  • 13
  • 2
  • Does this answer your question? ["does not contain a static 'main' method suitable for an entry point"](https://stackoverflow.com/questions/17095217/does-not-contain-a-static-main-method-suitable-for-an-entry-point) – WhiteSpidy. Jan 16 '21 at 14:50
  • 3
    This code by itself doesn't produce that error: https://dotnetfiddle.net/ipIdVm. It compiles/runs but doesn't do anything since you aren't executing any code in `Main()` – devNull Jan 16 '21 at 15:08

1 Answers1

-1

You have to change your code to this:

public class Program
{
    public static int a,b,c,d;

    public static void Main()
    {
      Start();
      Update();
    }
    
    public static void Start() 
    {
       .... your code
    }

    public static void Update() 
    {
           .... your code
    }
}

and use "dotnet run" inside of a VS Code terminal to execute the program

spottedmahn
  • 14,823
  • 13
  • 108
  • 178
Serge
  • 40,935
  • 4
  • 18
  • 45