2016-04-05 12 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; 
      } 
     } 
     } 
    } 
関連する問題