10-03-2008, 08:50
|
|
|
חבר מתאריך: 07.12.07
הודעות: 35
|
|
עזרה דחופה || עבודה ב C#
שלום.
התבקשנו בבית הספר להכין פרויקט ב C# ובחרתי בנושא גלגל המזל.
הכל עובד כמו שצריך חוץ מבעיה אחת שלא הצלחתי לפתור.
התוכנית צריכה לוודא שהמשתמש לא יכניס את אותה האות פעמיים.
עם מישהו יוכל לעזור לי בכתיבת הקוד ולא בלהגיד מה לעשות כי את זה כבר הרבה אמרו לי ולא הצלחתי לתרגם את זה.
תודה P:
הנה התוכנית:
קוד:
[] static void Main(string[] args)
{
string[] milim = new string[15];
int h, i, j, k;
string quit;
int mone = 0;
milim[0] = "pelephone";
milim[1] = "television";
milim[2] = "computer";
milim[3] = "ipod";
milim[4] = "mp3";
milim[5] = "playstation";
milim[6] = "xbox";
milim[7] = "speakers";
milim[8] = "leptop";
milim[9] = "vista";
milim[10] = "dvd";
milim[11] = "mouse";
milim[12] = "keyboard";
milim[13] = "plasma";
milim[14] = "camera";
Console.WriteLine();
Console.WriteLine("Welcome to the lucky round (galgal hamazal) game.");
Console.WriteLine();
Console.WriteLine("----------------------------------------------------------------------------");
Console.WriteLine();
Console.WriteLine("Instructions:");
Console.WriteLine();
Console.WriteLine("Enter a letter and the computer will tell you if this letter appear in the");
Console.WriteLine();
Console.WriteLine("word that he think about and how many tims.");
Console.WriteLine();
Console.WriteLine("** If the computer ask you for another letter it mean that this letter");
Console.WriteLine();
Console.WriteLine("doesn't appear in the word. **");
Console.WriteLine();
Console.WriteLine("----------------------------------------------------------------------------");
Console.WriteLine();
Console.WriteLine("Good luck =] ");
Console.WriteLine();
for (i = 0; i < 15; i++)
{
int orech = milim[i].Length;
char[] otiot = new char[milim[i].Length];
char ot;
for (h = orech; h > 0; h--)
{
Console.WriteLine();
Console.WriteLine("You have {0} tries left.", h);
Console.Write("Enter a letter: ");
ot = char.Parse(Console.ReadLine());
for (k = 0; k < orech; k++)
{
if (milim[i][k] == ot)
{
otiot[k] = ot;
mone++;
Console.WriteLine();
Console.WriteLine("You did it. You found {0} correct letters", mone);
Console.WriteLine();
for (j = 0; j < milim[i].Length; j++)
{
Console.Write(otiot[j]);
}
Console.WriteLine();
}
if (mone == milim[i].Length)
{
h = mone - 1;
}
}
}
for (j = 0; j < milim[i].Length; j++)
{
Console.Write(otiot[j]);
}
Console.WriteLine();
Console.WriteLine("You passed {0} words", i + 1);
Console.WriteLine();
Console.Write("The word was: ");
Console.WriteLine(milim[i]);
Console.WriteLine();
Console.WriteLine("Do you want to continue? (Yes or No) ");
quit = Console.ReadLine();
if ((quit == "no") || (quit == "No"))
{
i = 15;
}
}
|