עבור לתוכן

עזרה בתרגיל ב-C# - מערכים

Featured Replies

פורסם

התרגיל:

In the Israeli National Football League there are 12 teams. Each team has a number from 1 to 12.

you get pairs: t1,t2,s1,s2, where:

t1 – number of first team

t2 – number of second team

s1 – score of first team

s2 – score of second team

calculate the number of points that each team got, where:

Game won – 3 points

Game lost – 0 points

Game duce – 1 point

Print: for each team: team number and team points.

צריל לקלוט זוגות מספרים כאשר הראשון זה קב' א' והשני התוצאה של קב' א'

אח"כ קב' ב' והשני התוצאה של קב' ב' (במשחקים בניהם)

כשיש לי תקו זה מכניס לי 3 נק' לאחת הקב' וגם מתחרבש לי לפעמים בתוצאות אחרות.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace T170
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Team Number And Result: ");

//define new array with 12 teams
int[] array = new int[12];

array[0] = 0;
array[1] = 0;

for (int i = 0; i < 2; i++)
{
//read first team
int T1 = int.Parse(Console.ReadLine());

//read second team
int T2 = int.Parse(Console.ReadLine());

//read first team score
int S1 = int.Parse(Console.ReadLine());

//read second team score
int S2 = int.Parse(Console.ReadLine());

if (S1==S2)
{
array[0] +=1;
array[1] +=1;
}
else
{
if (S1>S2)
{
array[0] +=3;
}


else
{
array[1] +=3;
}
}
}

Console.WriteLine("Team Number 1 Number Of points: " + array[0]);
Console.WriteLine("Team Number 2 Number Of points: " + array[1]);
Console.ReadLine();
}
}
}

פורסם

אתה מכניס את כל התוצאות רק לשני המקומות הראשונים במערך, ומתעלם בכלל מהערכים של t1 ו-t2.

פורסם
  • מחבר

אני מכניס את כל התוצאות רק לשני המקומות הראשונים במערך כי בתרגיל ביקשו רק את התוצאות של 2 הקב' ולא את כל ה-12.

פורסם
  • מחבר

למה אני מתעלם מהערכים t1 ו-t2 ?

אמרתי שאם למשל S1 גדול יותר מ-S2 אז 3 נק' (ניצחון) הולכים לקב' 1 (תא מס' 0)

פורסם

תראה לי איפה בקוד שלך אתה משתמש בערכים שקראת לתוך T1 ו-T2.

פורסם
  • מחבר

אני לא קורא להם ולא הבנתי למה אני אמור אם למשל S1 גדול יותר מ-S2 אז אני מכניס 3 נק' לאינדקס אפס שהוא מייצג את קב' מספר 1

פורסם

אז למה אתה בכלל טורח לקרוא את T1 ו-T2 אם אתה לא משתמש בהם?

חוץ מזה, הקוד שלך לא תואם את התיאור שלך:

צריל לקלוט זוגות מספרים כאשר הראשון זה קב' א' והשני התוצאה של קב' א'

אח"כ קב' ב' והשני התוצאה של קב' ב' (במשחקים בניהם)

ולא ברור לי למה נועד ה-for.

ארכיון

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

דיונים חדשים