2014-01-12 15 views
-5

我的代碼:即使相同的教程代碼編譯,什麼使得我的代碼不能編譯?

using System: 
namespace Hero2 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      int herohitpoints, monsterhitpoints, attackdamage; 
      herohitpoints = 20; 
      monsterhitpoints = 15; 
      attackdamage = 8; 
      Console.WriteLine("The hero has {0}hp and the monster has {1}hp.", herohitpoints, monsterhitpoints); 
      do 
      { 
       herohitpoints -= attackdamage; 
       monsterhitpoints -= attackdamage; 
       Console.WriteLine("The hero attacks for {0}hp of damage", attackdamage); 
       Console.WriteLine("The monster attacks for {0}hp of damage", attackdamage); 
       Console.WriteLine("The hero now has {0}hp and the monster has {1}hp", herohitpoints, monsterhitpoints); 
       Console.ReadLine(); 
      } 
      while (herohitpoints >0&&monsterhitpoints>0); 
     } 
    } 
} 

這裏是我一直在複製下來的教程代碼:

using System; 
namespace Hero3 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      int herohitpoints, monsterhitpoints, attackdamage; 
      herohitpoints = 20; 
      monsterhitpoints = 15; 
      attackdamage = 8; 
      Console.WriteLine("The hero has {0}hp, and the monster has {1}hp", herohitpoints,monsterhitpoints); 
      do 
      {    
       herohitpoints -= attackdamage; 
       monsterhitpoints -= attackdamage; 
       Console.WriteLine("The hero attacks for {0}hp of damage", attackdamage); 
       Console.WriteLine("The monster attacks for {0}hp of damage", attackdamage); 
       Console.WriteLine("The hero now has {0}hp, and the monster has {1}hp",herohitpoints, monsterhitpoints); 
       Console.ReadLine(); 
      } 
      while (herohitpoints >0&&monsterhitpoints>0); 
     } 
    } 
} 

我已經花了一封信在最後一小時搜索通過這封信,試圖看到什麼這是我做錯了,但我無法在任何地方找到它。 從教程網站複製粘貼的代碼編譯和運行完美,但我的不會。我究竟做錯了什麼?

+2

很明顯,你沒有通過'逐個字母'的搜索' –

+0

**嚴重?**當把它放入Visual Studio的錯誤列表顯示';預計「和*突出顯示錯誤*。我不認爲一個問題要求兩個文件的差異是一個很好的使用StackOverflow。如果可以,我會-5。 – Harrison

+0

Ctrl + A然後按Ctrl + C第二塊代碼,然後按Ctrl + V在VS – Jim

回答

0

在開始時你需要一個;而不是:。 所以它應該是using System;,而不是using System:

+0

* FACEPALM *我怎麼沒注意到? XD一旦StackOverflow允許我將立即接受你的答案。 –

+0

@Prince_of_Oriel,在你提到的另一篇文章中,你使用的是Notepad ++而不是IDE。 IDE將幫助您找到像這樣的小錯誤。如果你不能獲得VS,[MonoDevelop](http://monodevelop.com/)是一個很好的選擇。 – pcnThird

+0

@pcnThird我在評論中還提到,由於相同的原因,我無法運行MonoDevelop,因此無法運行Visual Studio:我的電腦在Windows XP(Service Pack 2)上。 –