class Program
    {


        static void Main()
        {


            Console.WriteLine("Roll Nos." + " " + " Names" + " " + "score 1" + " " + "score 2" + " " + "score 3" + " " + "Average\n");
            Console.ReadLine();


             LinkedList<string> Linked = new LinkedList<string>();

            Linked.AddLast("maryam");
            Linked.AddLast("ali");
            Linked.AddLast("mahum");
            Linked.AddLast("aliza");
            Linked.AddLast("faizan");
            Linked.AddLast("mehreen");
            Linked.AddLast("arisha");
            Linked.AddLast("maira");
            Linked.AddLast("hira");
            Linked.AddLast("ameen");
            Linked.AddLast("fari");
            Linked.AddLast("kashif");
            Linked.AddLast("farhan");
            Linked.AddLast("abid");
            Linked.AddLast("mustafa");
            Linked.AddLast("urooj");
            Linked.AddLast("areeba");
            Linked.AddLast("anusha");
            Linked.AddLast("farheen");
            Linked.AddLast("zareen");
            Linked.AddLast("amber");
            Linked.AddLast("hammad");
            Linked.AddLast("fawad");
            Linked.AddLast("huriya");
            Linked.AddLast("yasir");
            Linked.AddLast("rafia");
            Linked.AddLast("maliha");
            Linked.AddLast("madiha");
            Linked.AddLast("sarwat");
            Linked.AddLast("noorisa");
            Linked.AddLast("meena");
            Linked.AddLast("hadi");
            Linked.AddLast("falak");
            Linked.AddLast("zubair");
            Linked.AddLast("eashal");
            Linked.AddLast("easha");
            Linked.AddLast("ramsha");
            Linked.AddLast("nabeel");
            Linked.AddLast("saleh");
            Linked.AddLast("salman");
            Linked.AddLast("mesam");
            Linked.AddLast("raza");
            Linked.AddLast("khurram");
            Linked.AddLast("saqib");
            Linked.AddLast("aylia");
            Linked.AddLast("fizza");
            Linked.AddLast("zaib");
            Linked.AddLast("aisha");
            Linked.AddLast("zoya");
            Linked.AddLast("marziya");
            Linked.AddLast("zainab");
            Linked.AddLast("noor");
            Linked.AddLast("maha");
            Linked.AddLast("rubab");
            Linked.AddLast("jaffar");
            Linked.AddLast("rohail");
            Linked.AddLast("malik");
            Linked.AddLast("mehtab");
            Linked.AddLast("shehryar");
            Linked.AddLast("jazib");
            Linked.AddLast("ameer");
            Linked.AddLast("tooba");
            Linked.AddLast("fatima");
            Linked.AddLast("abiha");
            Linked.AddLast("tehseen");
            Linked.AddLast("tazeen");
            Linked.AddLast("medhat");
            Linked.AddLast("sana");
            Linked.AddLast("iqra");
            Linked.AddLast("abid");
            Linked.AddLast("waleed");
            Linked.AddLast("nabiha");
            Linked.AddLast("nabila");
            Linked.AddLast("anita");
            Linked.AddLast("aleem");
            Linked.AddLast("mona");
            Linked.AddLast("shahid");
            Linked.AddLast("saba");
            Linked.AddLast("zoya");
            Linked.AddLast("anisa");
            Linked.AddLast("rabbiya");
            Linked.AddLast("bariha");
            Linked.AddLast("anila");
            Linked.AddLast("asra");
            Linked.AddLast("taaliya");
            Linked.AddLast("quratulain");
            Linked.AddLast("komal");
            Linked.AddLast("kainat");
            Linked.AddLast("muniba");
            Linked.AddLast("naeem");
            Linked.AddLast("dua");
            Linked.AddLast("wajahat");
            Linked.AddLast("waqar");
            Linked.AddLast("tabinda");
            Linked.AddLast("asad");
            Linked.AddLast("shoaib");
            Linked.AddLast("aabia");
            Linked.AddLast("misha");
            Linked.AddLast("anam");
            Linked.AddFirst("sobia");

            for (int i = 0; i <= 100; i = i + 1)
            {
                Console.Write(i);

                Console.ReadLine();
                Console.WriteLine(" ");
            }

            foreach (var names in Linked)
                {

                    Console.WriteLine(names);

                    Console.ReadLine();
                    Console.WriteLine(" ");
                }





            int avg, s1, s2, s3, N;


                Console.WriteLine("enter scores of 3 exams:");
                s1 = Convert.ToInt16(Console.ReadLine());
                s2 = Convert.ToInt32(Console.ReadLine());
                s3 = Convert.ToInt32(Console.ReadLine());




                avg = (s1 + s2 + s3) / 3;
                Console.WriteLine(avg);
                Console.ReadLine();




        }

    }
}

i am writing a program to find the average of 3 exam score's of each student having 100 enrollments using linked list and i cant display the names under the Names string and also to get scores either in array or throught user input and calculate the average .please someone kindly help me with this em attaching the code with this

Hmm, if i understood you correctly then what you want your code to do is to find a average grade of each one of the persons stored in the list. Is that right?

delete lines 10 & 120 & 129. This removes the blocks from printing out the names, etc.. In looking at your code it looks like you want to list the students by name and number them as well. I redid the code to do that as your code printed out a list of numbers then the list of names. Also I added a few more prompts, etc. at the end. Hopes this helps you to get to the next step.

sorry forgot to add the code lol This can replace lines 115-151:

            int Counter = 0;
            foreach (var names in Linked)
            {
                Counter ++;
                Console.WriteLine(Counter+" - "+ names);
                Console.WriteLine(" ");
            }
            int avg, s1, s2, s3, N;
            Console.WriteLine("enter scores of 3 exams:");
            Console.Write("First Score - ");
            s1 = Convert.ToInt16(Console.ReadLine());
            Console.Write("Second Score - ");
            s2 = Convert.ToInt32(Console.ReadLine());
            Console.Write("Second Score - ");
            s3 = Convert.ToInt32(Console.ReadLine());
            avg = (s1 + s2 + s3) / 3;
            Console.WriteLine("The Average is: "+avg);
            Console.ReadLine();

i actually want to print it vertically the roll no.s names and then the score's and calculated average of the three score's
and display for each student like the image below

static void Main(string[] args)
        {




            LinkedList<string> Linked = new LinkedList<string>();
            Linked.AddLast("maryam");
            Linked.AddLast("ali");
            Linked.AddLast("mahum");
            Linked.AddLast("aliza");
            Linked.AddLast("faizan");
            Linked.AddLast("mehreen");
            Linked.AddLast("arisha");
            Linked.AddLast("maira");
            Linked.AddLast("hira");
            Linked.AddLast("ameen");
            Linked.AddLast("fari");
            Linked.AddLast("kashif");
            Linked.AddLast("farhan");
            Linked.AddLast("abid");
            Linked.AddLast("mustafa");
            Linked.AddLast("urooj");
            Linked.AddLast("areeba");
            Linked.AddLast("anusha");
            Linked.AddLast("farheen");
            Linked.AddLast("zareen");
            Linked.AddLast("amber");
            Linked.AddLast("hammad");
            Linked.AddLast("fawad");
            Linked.AddLast("huriya");
            Linked.AddLast("yasir");
            Linked.AddLast("rafia");
            Linked.AddLast("maliha");
            Linked.AddLast("madiha");
            Linked.AddLast("sarwat");
            Linked.AddLast("noorisa");
            Linked.AddLast("meena");
            Linked.AddLast("hadi");
            Linked.AddLast("falak");
            Linked.AddLast("zubair");
            Linked.AddLast("eashal");
            Linked.AddLast("easha");
            Linked.AddLast("ramsha");
            Linked.AddLast("nabeel");
            Linked.AddLast("saleh");
            Linked.AddLast("salman");
            Linked.AddLast("mesam");
            Linked.AddLast("raza");
            Linked.AddLast("khurram");
            Linked.AddLast("saqib");
            Linked.AddLast("aylia");
            Linked.AddLast("fizza");
            Linked.AddLast("zaib");
            Linked.AddLast("aisha");
            Linked.AddLast("zoya");
            Linked.AddLast("marziya");
            Linked.AddLast("zainab");
            Linked.AddLast("noor");
            Linked.AddLast("maha");
            Linked.AddLast("rubab");
            Linked.AddLast("jaffar");
            Linked.AddLast("rohail");
            Linked.AddLast("malik");
            Linked.AddLast("mehtab");
            Linked.AddLast("shehryar");
            Linked.AddLast("jazib");
            Linked.AddLast("ameer");
            Linked.AddLast("tooba");
            Linked.AddLast("fatima");
            Linked.AddLast("abiha");
            Linked.AddLast("tehseen");
            Linked.AddLast("tazeen");
            Linked.AddLast("medhat");
            Linked.AddLast("sana");
            Linked.AddLast("iqra");
            Linked.AddLast("abid");
            Linked.AddLast("waleed");
            Linked.AddLast("nabiha");
            Linked.AddLast("nabila");
            Linked.AddLast("anita");
            Linked.AddLast("aleem");
            Linked.AddLast("mona");
            Linked.AddLast("shahid");
            Linked.AddLast("saba");
            Linked.AddLast("zoya");
            Linked.AddLast("anisa");
            Linked.AddLast("rabbiya");
            Linked.AddLast("bariha");
            Linked.AddLast("anila");
            Linked.AddLast("asra");
            Linked.AddLast("taaliya");
            Linked.AddLast("quratulain");
            Linked.AddLast("komal");
            Linked.AddLast("kainat");
            Linked.AddLast("muniba");
            Linked.AddLast("naeem");
            Linked.AddLast("dua");
            Linked.AddLast("wajahat");
            Linked.AddLast("waqar");
            Linked.AddLast("tabinda");
            Linked.AddLast("asad");
            Linked.AddLast("shoaib");
            Linked.AddLast("aabia");
            Linked.AddLast("misha");
            Linked.AddLast("anam");
            Linked.AddFirst("sobia");

            int avg;


            int[] s1 ={ 100,88,90,34,56,78,88,90,80,76,
                         45,87,66,74,43,30,60,50,48,89,
                         97,65,55,45,33,31,46,95,50,80,
                         20,29,84,83,54,64,95,69,90,97,
                         45,87,66,74,43,30,60,50,48,89,
                         100,88,90,34,56,78,88,90,80,76,
                         97,65,55,45,33,31,46,95,50,80,
                         27,29,84,83,54,64,95,69,90,78,97,
                         65,55,45,33,31,46,95,50,80,
                      };
            int[] s2 ={20,29,84,83,54,64,95,69,90,97,
                         45,87,66,74,43,30,60,50,48,89,
                         100,88,90,34,56,78,88,90,80,76,
                         97,65,55,45,33,31,46,95,50,80,
                         27,29,84,83,54,64,95,69,90,78,97,
                         65,55,45,33,31,46,95,50,80,
                         45,87,66,74,43,30,20,29,84,83,54,64
                         ,95,69,90,97,60,50,48,89,97,65,55,45,33,31,
                         46,95,50,80,100,88,90,34,56,78,88,90,80,76};
            int[] s3 ={97,65,55,45,33,31,46,20,29,84,20,
                          29,84,83,54,64,95,69,90,97,
                         45,87,66,74,43,30,60,50,48,89,
                         100,88,90,34,56,78,88,90,80,76,
                         97,65,55,45,33,31,46,95,50,80,
                         27,29,84,83,54,64,95,69,90,78,97,
                         65,55,45,33,31,46,95,50,80,
                         83,54,64,95,69,90,97,95,50,80,
                         100,88,90,34,56,78,88,90,80,76,
                         45,87,66,74,43,30,60,50,48,89,};







            Console.WriteLine("Roll Nos." + " " + " Names" + " " + "score 1" + " " + "score 2" + " " + "score 3" + " " + "Average\n");

            int Counter = 0;

            foreach (var names in Linked)
            {
                for (int i = 0; i < s1.Length; i++)
                {
                    avg = (s1[i] + s2[i] + s3[i]) / 3;


                    Counter++;
                    Console.WriteLine(Counter + "          " + names + "   " + s1[i] + "       " + s2[i] + "      " + s3[i] + "       " + avg);
                }
                Console.ReadLine();

            }
        }


    }
}

i got it in that way but now it prints the same name again and again what changes should i make ? :S

Try this

 Console.WriteLine("Roll Nos." + " " + " Names" + " " + "score 1" + " " + "score 2" + " " + "score 3" + " " + "Average\n");
int Counter = 0;
foreach (var names in Linked)
{

avg = (s1[Counter] + s2[Counter] + s3[Counter]) / 3;
Counter++;
Console.WriteLine(Counter + " " + names + " " + s1[Counter] + " " + s2[Counter] + " " + s3[Counter] + " " + avg);

Console.ReadLine();
}

If you run the previous code you'll come across one of the pitfalls of trying to align spearate pieces of information. If any one of them gets missed you get an error, but the error doesn't show at the one you missed only at the last one. Which means you have to physically examine each piece to find what was missed. I've put together a sample for you to show how to do the same thing with a struct.:

        public struct Student
        {
            public int Roll_No;
            public string Name;
            public int[] Score ;
            public int Avg;
        }

        //I want to get data like this;


        static void Main(string[] args)
        {
            List<Student> Students = new List<Student>(); 
            foreach (string Line in ConsoleApplication2.Properties.Resources.TextFile1.Split('\n'))
            {
                if (Line != "")
                {
                    Student TempStudent = new Student();
                    string[] Info = Line.Split(' ');
                    TempStudent.Roll_No = Convert.ToInt32(Info[0]);
                    TempStudent.Name = Info[1].PadRight(15);
                    TempStudent.Score = new int[] { Convert.ToInt32(Info[2]), Convert.ToInt32(Info[3]), Convert.ToInt32(Info[4]) };
                    TempStudent.Avg = Convert.ToInt32(Info[5]);
                    Students.Add(TempStudent);
                }
            }


            Console.WriteLine("Roll Nos. " + "Names\t\t" + "score 1\t"+ "score 2\t"+ "score 3\t"+ "Average\n");
            foreach (var Person in Students)
            {
                Avg = Person.Score.Average();
                Console.WriteLine(Person.Roll_No+ "\t" + Person.Name + "\t  " + Person.Score[0] + "\t" + Person.Score[1] + "\t" + Person.Score[2] + "\tAvg. - " + Person.Avg);
            }
            Console.ReadLine();
        }

In this sample I loaded the info you had into a text file with each line containing the students info(i.e."1 sobia 88 29 65 72"). I put the text file into a folder called 'Resources' in folder for this project. Then in the project properties added the file to the resources. One advantage of this is you code doesn't get cluttered with all the data you need. One change you might want to make is the Averages. Instead of having them in the text file you can add them at run time by using this,TempStudent.Avg = TempStudent.Score.Average();. Hope this helps.

Thanks alot it is working now as i wanted :)

You're Very Welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.