2012-10-21 35 views
2

任何人都可以告訴我爲什麼我得到這個錯誤?這是我第一次發佈此論壇。我已經做了一些自己解決問題的研究,說我可能在某處有一個不正確的花括號,但我找不到它。任何幫助是極大的讚賞。爲什麼我得到錯誤「預期的類,委託,枚舉,接口或結構」


using System; 

    class Program 
    { 
    //declare constant 
    const double ANGLES_FROM_RADIANS = 57.295779513082323; 

    static void Main() 
    { 

     //declare vairiables 
     double xc = 0.0; 
     double yc = 0.0; 
     double radius = 0.0; 
     double theta = 0.0; 

     //call methods 
     double GetUserInput (ref double xc, ref double yc); 
     double CalcCoords (double xc, double yc, ref double radius, ref double theta); 
     double Output (double radius, double theta); 
    } 


    //method prologue 

    static double GetUserInput (ref double xc, ref double yc) 
    { 
     xc = 0; 
     yc = 0; 
     while (xc = 0) 
     { 
    Console.WriteLine("Please enter a possitive, non-zero value for the x-ccordinate of a point."); 
      xc = int.Parse(Console.ReadLine()); 
      if (xc <= 0) 
      { 
       Console.WriteLine("Error, x must be greater than zero."); 
      } 
     } 
     Console.WriteLine("Please enter a possitive value for the y-coordinate of a point."); 
     yc = int.Parse(Console.ReadLine()); 

     Return Console.WriteLine("Your Coordinates are ({0},{1})", xc, yc); 
    } 

    //method prologue 
    static double CalcCoords (double xc, double yc, ref double radius, ref double theta) 
    { 
      { 
      radius = Math.sqrt((xc * yc) + (xc * yc)); 
      return radius; 
      } 
      { 
      theta = Math.Atan(yc/xc) * ANGLES_FROM_RADIANS; 
      return theta; 
     } 
    } 

    //method prologue 
    static double Output (double radius, double theta) 
    { 
     Console.WriteLine("For your polar coordinates:"); 
     Console.WriteLine("Distance from the origin: {0:f}", radius); 
     Console.WriteLine("The angle (in degrees) from the x-axis is: {0:f3}", theta); 
    } 

     Console.ReadLine(); 

    }//End Main() 
    }//End class Program 

回答

4

最後一個大括號是多餘的隊友。這一個 -

}//End Main() 

而且爲什麼最後Console.ReadLine();misplaced。它不應該在任何方法範圍內?

編輯

我不知道什麼假設你的代碼做。它包含很多errorsintent of code也不清楚。此代碼雖然編譯 -

class Program 
    { 
     //declare constant 
     const double ANGLES_FROM_RADIANS = 57.295779513082323; 

     static void shdg() 
     { 
      //declare vairiables 
      double xc = 0.0; 
      double yc = 0.0; 
      double radius = 0.0; 
      double theta = 0.0; 
     } 

     //method prologue 
     static void GetUserInput(ref double xc, ref double yc) 
     { 
      xc = 0; 
      yc = 0; 
      while (xc == 0) 
      { 
       Console.WriteLine("Please enter a possitive, non-zero value for the x-ccordinate of a point."); 
       xc = int.Parse(Console.ReadLine()); 
       if (xc <= 0) 
       { 
        Console.WriteLine("Error, x must be greater than zero."); 
       } 
      } 
      Console.WriteLine("Please enter a possitive value for the y-coordinate of a point."); 
      yc = int.Parse(Console.ReadLine()); 

      Console.WriteLine("Your Coordinates are ({0},{1})", xc, yc); 
     } 

     //method prologue 
     static double CalcCoords(double xc, double yc, ref double radius, ref double theta) 
     { 
      { 
       radius = Math.Sqrt((xc * yc) + (xc * yc)); 
       return radius; 
      } 
      { 
       theta = Math.Atan(yc/xc) * ANGLES_FROM_RADIANS; 
       return theta; 
      } 
     } 

     //method prologue 
     static void Output(double radius, double theta) 
     { 
      Console.WriteLine("For your polar coordinates:"); 
      Console.WriteLine("Distance from the origin: {0:f}", radius); 
      Console.WriteLine("The angle (in degrees) from the x-axis is: {0:f3}", theta); 
     } 
    }//End class Program 
+0

所以我刪除了最後一個大括號,並沒有清除我的錯誤...任何其他的想法? – BXL

+0

您是否刪除了最後一個在類代碼中的最後一個'Console.ReadLine()'? –

+0

是的,我有。它也沒有清除錯誤。 – BXL

2

額外的最後一個大括號}//End Main()

0

main methodmethod犯規包含class或其他方法

一個class包含單個main方法(這是入口點您的應用)或/和倍數methods

另外你的//call methods是無效的..你必須傳遞值或變量。

+0

一個類可以沒有入口點,並且op在他的代碼中有一個入口點。 –

+0

@CodeIgnoto爲什麼我說**或/和** – Anirudha

+0

我不確定你的意思是假。對不起,我對此很新。 – BXL

相關問題