You got this compile error because this line is never executed:
int hak = 3;
It is because of the GOTOs, the position of the LABELS and the test condition if...else
above this line: you never pass this line.
To solve this compile error as well as the design problem which is thus generated, you need to refactor all that to remove all the GOTOs.
Indeed, when compiling, before talking about executing, the if ( komut == '1' ) ... else ...
, the hak
creation in never reached, going to GIRIS
or END
.
Thus after when you try to use hak
, it never was assigned and the compiler know that and tell you that.
Just to get to compile, you need to write:
GIRIS:
int hak = 3;
But using GOTOs is trashy and not clean, a very bad smell, as well as being source of mistakes and weird behaviors.
Avoid goto more than one once per century, and use refactoring instead, please.
GOTO still considered harmful?
Spaghetti code
Example of a minimal solution using a local method
if ( komut == '1' )
{
int hak = 3;
GIRIS(ref hak);
}
else
{
Console.Write("??k?? yapt?n?z. ?yi günler dileriz.");
}
Console.ReadKey();
void GIRIS(ref int hak)
{
Console.Write("Lütfen Kullan?c? Ad?n?z? Giriniz: ");
string kullanici_adi_giris = Console.ReadLine();
Console.Write("Lütfen belirlemi? oldu?unuz ?ifrenizi giriniz: ");
string sifre_giris = Console.ReadLine();
int karsilastirma_k_adi = String.Compare(kullanici_adi, kullanici_adi_giris);
int karsilastirma_sifre = String.Compare(sifre, sifre_giris);
if ( karsilastirma_k_adi == 0 && karsilastirma_sifre == 0 )
{
Console.Write("Ba?ar?yla Giri? Yapt?n?z. Ho?geldiniz.");
}
else if ( hak == 0 )
{
Console.Write("3 defa yanl?? giri? yapt?n?z. Mü?teri hizmetleri temsilcisiyle g?rü?ünüz. ?yi günler dileriz.");
}
else
{
hak--;
Console.WriteLine("Hatal? Giri? Yapt?n?z. Lütfen tekrar deneyiniz. {0} hakk?n?z kalm??t?r.", hak);
GIRIS(ref hak);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…