What am I doing wrong on this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What am I doing wrong on this code?

So for this problem, I am basically writing a program that takes the numbers of each day's winners as input and output them. The jagged array represents the list of all participants divided by the number of days. The thing is that I'm trying to use a nested for loop for the solution. However, it is not outputting anything. Here is the code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int day1Winner = Convert.ToInt32(Console.ReadLine()); int day2Winner = Convert.ToInt32(Console.ReadLine()); int day3Winner = Convert.ToInt32(Console.ReadLine()); string[][] olympiad = new string[][] { //day 1 - 5 participants new string[] { "Jill Yan", "Bridgette Ramona", "Sree Sanda", "Jareth Charlene", "Carl Soner" }, //day 2 - 7 participants new string[] { "Anna Hel", "Mariette Vedrana", "Fran Mayur", "Drake Hilmar", "Nikolay Brooks", "Eliana Vlatko", "Villem Mario" }, //day 3 - 4 participants new string[] { "Hieremias Zavia", "Ziya Ollie", "Christoffel Casper", "Kristian Dana", } }; //your code goes here string x = olympiad[][]; for (int a = 1; a < 5; a++) { for (int b = 0; b < 7; b++) { for (int c = 0; c < 4; c++) { Console.Write(olympiad[0][1][2]); } } Console.WriteLine(x); } } } } Can someone explain to me what is wrong with this code?

6th Apr 2023, 7:30 PM
Gradi Maxime Kasita Mbatika
3 Answers
+ 2
May I ask why do you think you need nested loops? You don't need to print all of the elements in the array.
6th Apr 2023, 8:40 PM
Ausgrindtube
Ausgrindtube - avatar
0
Ausgrindtube, it is because I thought that nested loops could help print out an element when the user is trying to input a number, as it will output a player inside the olympiad array. That's what I was thinking.
6th Apr 2023, 9:50 PM
Gradi Maxime Kasita Mbatika
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int day1Winner = Convert.ToInt32(Console.ReadLine()); int day2Winner = Convert.ToInt32(Console.ReadLine()); int day3Winner = Convert.ToInt32(Console.ReadLine()); string[][] olympiad = new string[][] { //day 1 - 5 participants new string[] { "Jill Yan", "Bridgette Ramona", "Sree Sanda", "Jareth Charlene", "Carl Soner" }, //day 2 - 7 participants new string[] { "Anna Hel", "Mariette Vedrana", "Fran Mayur", "Drake Hilmar", "Nikolay Brooks", "Eliana Vlatko", "Villem Mario" }, //day 3 - 4 participants new string[] { "Hieremias Zavia", "Ziya Ollie", "Christoffel Casper", "Kristian Dana", } }; //your code goes here Console.WriteLine(olympiad[0][day1Winner-1]); Console.WriteLine(olympiad[1][day2Winner-1]); Console.WriteLine(olympiad[2][day3Winner-1]); } } }
25th Apr 2024, 6:53 AM
Infos and Facts
Infos and Facts - avatar