-3

`

for(int i=0;i<jagged.Length;i++)
{
for(int j=0;j<jagged[i].Length;i++)
{
jagged[i][j] = Convert.ToInt32(Console.ReadLine());
}
}

` i want this piece of code to take 2 score inputs in jagged[0] and 3 score inputs in jagged1 but it is taking 5 inputs in both the cases.

jagged array input problem

For "n" number of teams with "at" attempts, i want to store the scores of these teams in "at" attempts in the jagged array example : if used inputs n = 2 and at= 2 for the first team. a jagged[2][2] should be created, i want to store the scores in this way- jagged[0] should be = new int[2]; (which i did at line 15) The lines starting from 21 are supposed to store these scores, but when i run the program, it takes input of scores more than the Length. What i want is - jagged[0][0] should store the first score input jagged0 should store the second score input and it should stop there. but it doesnt , it takes input 3 more times.(5 times total)

Similarly, the attempts for 2nd team is input as 3 and still it is taking the input 2 more times (5 times total)

  • 1
    Images of code are not acceptable on this site. Please post your code in your question text. To format it as code, prefix each line with 4 spaces. – ProgrammingLlama Jun 30 '20 at 23:36
  • Do not post an image of your code. Please [edit] your question and add a relevant code block, please. – John Alexiou Jun 30 '20 at 23:38
  • You don't need second for loop of `for(int i =0 ; i – Chetan Jun 30 '20 at 23:46
  • I added a piece of code, Is it any helpful? – Harshit Chepe Jun 30 '20 at 23:48
  • You're expected to add a [mcve]. That means that the code you provide needs to be sufficient for us to use it to reproduce your problem. If I paste the code you have provided into Visual Studio, I get errors telling me that `jagged` and `jag` don't exist. More specifically: from the code you have posted, it's unclear how `jagged` and `jag` are defined. – ProgrammingLlama Jun 30 '20 at 23:50
  • @ChetanRanpariya I need that for loop for Displaying the team number i.e Enter the score for team i+1 (1,2,3,4,...) – Harshit Chepe Jun 30 '20 at 23:50
  • Put that inside `j` for loop – Chetan Jun 30 '20 at 23:51
  • Thank you so much @ChetanRanpariya. I feel ashamed not figuring out such an easy thing. Thanks a lot again! :) – Harshit Chepe Jun 30 '20 at 23:54

1 Answers1

-2

You are using a triple cicle, but you just need 2. Remove the k for cicle,and change the condition for the j cicle to j <jag[i].Length

DkAngelito
  • 1,147
  • 1
  • 13
  • 30