עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

שאלה שאני לא מצליח לפתור C#

Featured Replies

פורסם

שלום לכולם.

יש פה איזה שאלה שאני יושב עליה כבר חצי שעה ולא הולך לי.

כשניסתי לעשות זה מה שיצא

      int num_of_people;

Console.WriteLine ("enter num of people");
num_of_people = int.Parse(Console.ReadLine());
char[] name = new char[num_of_people];
for (int i = 0; i < num_of_people; i++)
{
name[i] = char.Parse(Console.ReadLine());
}
for (int i=0; i < 3; i++)
{
Console.WriteLine(name[name.Length - i]);
}

אבל זה נותן שגיאה.

אגב במקום שמות תעשו רק CHAR כי STRING ירד במיקוד ( :funn: )

תודה מראש!

[attachment deleted by admin]

פורסם

קודם כל, לא הבנתי מה ניסית לעשות בלולאה השנייה (מאיפה הבאת את המספר 3?)

דבר שני, יעזור אם תגיד מה השגיאה.

דבר שלישי, יש לך שגיאה בלולאה השנייה - שים לב שבאיטרציה הראשונה, אתה למעשה מבצע:

Console.WriteLine(name[name.Length]);

(כי i==0)

וזו שגיאה, כי כשניגשים למערך אז מותר לגשת מ-0 ועד לאורך המערך פחות 1 (כלומר אם המערך בגודל 10, אז אתה יכול לגשת לתאים במקומות 0 עד 9, ולא 1 עד 10).

פורסם

פיתרון אפשרי : (פתרתי גם בשבילי )

Console.WriteLine("How many tourists?");
int tourists = int.Parse(Console.ReadLine());
char[] tourOrder = new char[tourists];
int i; char temp=',';
for (i = 0; i < tourOrder.Length; i++)//קליטת נתונים
{
Console.WriteLine("Insert the char of tourist number : {0}", i + 1);
tourOrder[i] = char.Parse(Console.ReadLine());
}
i = 0;
for (int minute = 1; minute < 75; minute++)// שעה ורבע שווה 75 דקות מן הסתם/ מתחילים מ1 כי 0 לא טוב
{
if(minute%20==0)//רק אם עברו 20 דקות אז להחליף מקום
{
temp = tourOrder[i];
for (int j = 0; j < tourOrder.Length-1; j++)//לולאה שמחליפה כל אות באות שאחריה
{
tourOrder[j] = tourOrder[j + 1];
}
tourOrder[tourOrder.Length - 1] = temp; //העברה של האות הראשונה למקום האחרון
}
}
Console.WriteLine();
for (i = 0; i < tourOrder.Length; i++) //לולאה שמדפיסה
Console.Write(tourOrder[i]);
Console.WriteLine();

פורסם

הפתרון שלך יפה ונכון לטעמי...

רק שיניתי דבר שנראה לי מיותר:

Console.WriteLine("How many tourists?");
int tourists = int.Parse(Console.ReadLine());
char[] tourOrder = new char[tourists];
int i; char temp=',';
for (i = 0; i < tourOrder.Length; i++)//קליטת נתונים
{
Console.WriteLine("Insert the char of tourist number : {0}", i + 1);
tourOrder[i] = char.Parse(Console.ReadLine());
}
i = 0;
for (int order = 1; order <= 3; order++)// שעה ורבע שווה 75 דקות מן הסתם/ מתחילים מ1 כי 0 לא טוב
{
temp = tourOrder[i];
for (int j = 0; j < tourOrder.Length-1; j++)//לולאה שמחליפה כל אות באות שאחריה
{
tourOrder[j] = tourOrder[j + 1];
}
tourOrder[tourOrder.Length - 1] = temp; //העברה של האות הראשונה למקום האחרון
}
Console.WriteLine();
for (i = 0; i < tourOrder.Length; i++) //לולאה שמדפיסה
Console.Write(tourOrder[i]);
Console.WriteLine();

-שים לב שהדבר היחידי שעשיתי, זה לשנות את הלולאה השניה, כך שתתבצע 3 פעמים, ומחקתי את התנאי המיותר מאחר וידוע לנו שהטיול נמשך כשעה ורבע,

ושכל 20 דקות מתחלף הסדר - כלומר, בשעה ורבע, מתחלף הסדר 3 פעמים.

במידה והיינו צריכים לקלוט את זמן הטיול, הגבול העליון של הלולאה השנייה פשוט היה time / 20.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.