2016-04-05 42 views
-3

所以我有這個登錄嘗試循環名爲'Inlogpoging'。 3次後,它需要給你的消息「登錄有限」。但是我在腳本的最後得到錯誤,它有什麼不對?不能調用int,即使我公開它

static void Main(string[] args) 
{ 
    for (int inlogpoging = 0; inlogpoging < 3; inlogpoging++) 
    { 
     Console.WriteLine("Status: " + status.Onaangemeld); 
     Console.Write("Gebruikersnaam:"); 
     string Naam = Console.ReadLine(); 

     Console.Write("Wachtwoord:"); 
     string Wachtwoord = Console.ReadLine(); 

     if (Naam == "administrator" && Wachtwoord == "SHARPSOUND") 
     { 
      Console.Clear(); 
      Console.WriteLine("Status: " + status.Ingelogd); 
      Console.WriteLine("Welkom bij SoundSharp {0}!", Naam); 
      Console.ReadLine(); 
      break; 
     } 

     Console.Clear(); 
     Console.WriteLine("Helaas, gebruikersnaam of wachtwoord niet correct."); 
    } 

    if (int inlogpoging == 3); //Right here <-- 
    { 
     Console.Clear(); 
     Console.WriteLine("Login limited."); 
    } 
} 
+0

它的語法錯誤'如果(inlogpoging == 3)'就足夠了,不要把分號有 – Chidchai

+0

@未除幸運單一的空白行沒有幫助,它積極有害可讀性。這不是一個好的編輯 –

回答

2

您在if附近有語法錯誤; if內部不允許聲明,這些聲明用於評估條件。也沒有必要用;終止他們下面的代碼可以幫助你:

int inlogpoging = 0; 
for (; inlogpoging < 3; inlogpoging++) 
    { 
     // do the operations here 
    } 
// change the if as below 
if (inlogpoging == 3) 
    { 
     Console.Clear(); 
     Console.WriteLine("Login limited."); 
    } 
0

我想你想你的代碼沒有做。 考慮下面的代碼,檢查意見:

static void Main(string[] args) 
     { 

     int inlogpoging = 0;//initialize int counter 
     while(inlogpoging<3) 
     { 
      if (inlogpoging == 3) //if equal to 3 then stop loguin process 
      { 
      Console.Clear(); 
      Console.WriteLine("Login limited."); 
      } 
      else {//if not 3 then process loguin 
      Console.WriteLine("Status: " + status.Onaangemeld); 
      Console.Write("Gebruikersnaam:"); 
      string Naam = Console.ReadLine(); 

      Console.Write("Wachtwoord:"); 
      string Wachtwoord = Console.ReadLine(); 

      //at this point increment counter 
      inlogpoging++; 

      if (Naam == "administrator" && Wachtwoord == "SHARPSOUND") 
      { 
       Console.Clear(); 
       Console.WriteLine("Status: " + status.Ingelogd); 
       Console.WriteLine("Welkom bij SoundSharp {0}!", Naam); 
       Console.ReadLine(); 

       Console.Clear(); 
       Console.WriteLine("Helaas, gebruikersnaam of wachtwoord niet  correct."); 


       //need a exit point 
       return 0; 
      } 
     } 
     } 
    } 
相關問題