2016-09-09 15 views
-2

CS1001 =識別子が必要ですコンパイルエラーCS1001。 JavaをCに変換する

C#でテストしたいコードをJavaから抜粋しました。それは私が使用したいビデオゲームプロジェクトでレベルアップするために必要な経験を計算するための公式を持っています。私はちょうど最近自分自身のコードを教え始めたので、これを変換するのは試行錯誤でしたが、私は他の13のエラーを取り除きました。

識別子が見つからないというのはかなり基本的な問題だと思われますが、あまりにも曖昧で、いつ調査を開始するのか分かりません。エラーが発生した箇所にコメントがあります。

ヒント

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

namespace ConsoleApplication1 
{ 
class Program 
{ 
    float points = 0; 
    double output = 0; // Output, XP total at level 
    float minLevel = 2; // First level to Display 
    int maxLevel = 100; // Last Level to Display 
    int lvl = 0; 

    void Main() 
    { 

     for (lvl = 1; lvl <= maxLevel; lvl++) 
     { 
      points += Math.Floor(lvl + 300 * Math.Pow(2, lvl/7.)); // Compile Error CS1001 at "));" 
      if (lvl >= minLevel) 
       Console.WriteLine("Level " + (lvl) + " - " + output + " EXP"); 
      output = Math.Floor(points/4); 
     } 
    } 
} 

}

オリジナルのJavaScriptコード:唯一の問題のように見えない

<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
document.close(); 
document.open(); 
document.writeln('Begin JavaScript output:'); 
document.writeln('<PRE>'); 

points = 0; 
output = 0; 
minlevel = 2; // first level to display 
maxlevel = 200; // last level to display 

for (lvl = 1; lvl <= maxlevel; lvl++) 
{ 
    points += Math.floor(lvl + 300 * Math.pow(2, lvl/7.)); 
    if (lvl >= minlevel) 
    document.writeln('Level ' + (lvl) + ' - ' + output + ' xp'); 
    output = Math.floor(points/4); 
} 

document.writeln('</PRE>'); 
document.close(); 
// --> 
</SCRIPT> 
+0

points + = Math.Floor(lvl + 300 * Math.Pow(2、lvl)/7.0)); –

+1

'7.)'?それは '7.0 'ではないはずです)'? –

+1

Java!== JavaScript ... –

答えて

1

... :)

を参照してください。インラインコメント:

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

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     float points = 0; 
     double output = 0; 
     float minLevel = 2; 
     int maxLevel = 100; 
     int lvl = 0; 

     void Main() //<-- Bad entry point public static void Main() 
     { 

      for (lvl = 1; lvl <= maxLevel; lvl++) 
      { 
       points += (float)Math.Floor(lvl + 300 * Math.Pow(2, lvl/7.)); // <-- You have to explicitly specify the mantissa if you have a '.' is should be 7.0 or 7f 
          //^--- You also need to cast to a float here because the expression evaluates to a double 
       if (lvl >= minLevel) 
        Console.WriteLine("Level " + (lvl) + " - " + output + " EXP"); 
       output = Math.Floor(points/4); 
      } 
     } 
    } 
} 
+0

テンプレートは 'static void Main()'を使い、変数を定義するときには 'static'と定義しなければならなかったので、両方の部分から静的を取り除いてテストしました。エラーはありません。私はそれらを置き忘れた。 –

+0

いくつかの_build errors_は、実際に 'build'を押すとVSにしか現れません –

関連する問題