Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BRACKEYS - Solution to C# Tutorial 05 Challenge

2»

Comments

  • I did mine a bit different but got the same result, also thx for these tutorials, they've been really helping me out in learning how to code.


    using System;

    using System.Collections.Generic;


    namespace My_Awrsome_Program

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Write("How many students are in your class: ");

                int students;

                students = Convert.ToInt32(Console.ReadLine());


                string[] amountOfStudents = new string[students];


                Console.WriteLine("Please name them all: ");

                

                for (int i = 0; i < students; i++)

                {

                    amountOfStudents[i] = Console.ReadLine();

                }

                

                Console.WriteLine("-------------------------");


                Array.Sort(amountOfStudents);

                for (int i = 0; i < students; i++)

                {

                    Console.WriteLine(amountOfStudents[i]);

                }

                


                // Wait before closing

                Console.ReadKey();

            }

        }

    }

  • NIGHT_C0DENIGHT_C0DE Member
    edited March 2021

    using System;

    using System.Collections.Generic;


    namespace New_Program_2

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.WriteLine("How many students do you have in your class: "); 

                int students;

                students = Convert.ToInt32(Console.ReadLine());

                

                string[] AmountofStudents = new string[students];


                Console.WriteLine("Please Name Them all");


                for (int i = 0; i < students; i++)

                {

                    AmountofStudents[i] = Console.ReadLine();

                }


                Console.WriteLine("---------------------------");


                Array.Sort(AmountofStudents);


                for (int i = 0; i < AmountofStudents.Length; i++)

                {

                    Console.WriteLine(AmountofStudents[i]);

                }


               // Waits Before Closing

               Console.ReadKey();

            }

        }

    }




    I am a bit late casue i just joiend brakeys

  • This is mine


    using System;
    
    
    
    namespace My_Awesome_Program
    {
        class Program
        {
            
            static void Main(string[] args)
            {
                Console.WriteLine("How many students do you have: "); 
              int numStudents = Convert.ToInt32(Console.ReadLine()); 
           
           
           string[] students = new string[numStudents]; 
           
            Console.WriteLine("OK! Now who are they:  ");
            for (int i = 0; i < students.Length; i++)
            {
                students[i] = Console.ReadLine();
            }
           
           
           Console.WriteLine("\nHere they are alphabetically:   ");
    
    
           Array.Sort(students);
    
    
           for (int i = 0; i < students.Length; i++)
           {
               Console.WriteLine(students[i]);
           }
           
           
           // Wait Before Closing 
            Console.ReadKey();
           } 
    
    
        }
    }
    
    
    
  • Mo_Mo_ Member

    Heres my solution for this one. Had a lot of problems with this one lol.

     {
     // Getting amount
    
    
    
    
                Console.WriteLine("Enter the amount of students: ");
    
    
    
    
                int amount = Convert.ToInt32(Console.ReadLine());
    
                string[] names = new string[amount];
    
    
    
    
                // Getting names
    
    
    
    
                Console.WriteLine("Please enter the names of the students: ");
    
    
    
    
                for (int i = 0; i < amount; i++)
    
                {
    
                    names[i] = Console.ReadLine();
    
                }
    
                // Printing names
    
                Array.Sort(names);
    
    
    
    
                Console.WriteLine("-----------");
    
                Console.WriteLine("Here they are alphabetically sorted: ");
    
    
    
    
                for (int i = 0; i < amount; i++)
    
                {
    
                     Console.WriteLine(names[i]);
    
                }
    
    
    
    
                // Wait
    
                Console.ReadKey();
    
            }
    
        }
    
    }
    

               

  • using System;
    
    namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Title = "BRACKEYS THE BEST";
                
                int amount;
                Console.Write("How many students are in your class: ");
                amount = Convert.ToInt32(Console.ReadLine());
                string[] students = new string[amount];
                Console.WriteLine("Please input the names of the students: ");
                for (int i = 0; i < amount; i++)
                {
                    students[i] = Console.ReadLine();
                }
                Console.WriteLine("----------------");
                
                Array.Sort(students);
                for (int i = 0; i < amount; i++)
                {
                    Console.WriteLine(students[i]);
                }
                
                
                
                
                // wait before close
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\nPress Enter to exit..");
                Console.ReadKey();
            }
        }
    }
    
    


  • NexNex Member

    Assignment 5:

    using System;
    
    namespace C__Assignment5
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Input the value of array size
                Console.WriteLine("Enter the number of students in your class: ");
                int students = Convert.ToInt32(Console.ReadLine());
                string[] class1 = new string[students];
                //Input the values inside the array
                Console.WriteLine("Write the name of the students: ");
    
                for (int i = 0; i < class1.Length; i++)
                {
                    class1[i] = Console.ReadLine();
                }
                //Arrange the array alphabetically:
                Console.WriteLine("\nArranging the students roster alphabetically...");
                Console.WriteLine("------------------------------------------------");
    
                Array.Sort(class1);
    
                for (int i = 0; i < class1.Length; i++)
                {
                    Console.WriteLine(class1[i]);
                }
                //Wait before closing
                Console.ReadKey();
            }
        }
    }
    
  • using System;


    namespace Tutorial

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Title = "Challenge By Brackeys!";


                int totalStudents;


                // Amount of students in the class

                Console.WriteLine("How many students are in your class: ");

                totalStudents  = Convert.ToInt32(Console.ReadLine());


                string[] Students = new string[totalStudents];


                // Names of the students

                Console.WriteLine("Please input the names of the students: ");


                for (int i = 0; i < totalStudents; i++)

                {

                    Students[i] = Console.ReadLine();

                }


                // Seperating students and sorting them by name

                Console.WriteLine("--------------------");


                Array.Sort(Students);

                for (int i = 0; i < totalStudents; i++)

                {

                    Console.WriteLine(Students[i]);

                }

                // Manually closing dotnet console

                Console.WriteLine("\nPress any key to exit");

                Console.ReadKey();

            }   

        }    

    }  

  • AkshayAkshay Member
     Console.Write("How many students are in your class: ");
    
    
                int studentCount = Convert.ToInt32(Console.ReadLine());
    
    
                Console.WriteLine("Please input the names of the students: ");
    
    
                string[] students = new string[studentCount];
    
    
                for (int i = 0; i < studentCount; i++)
                {
                    students[i] = Console.ReadLine();
                }
    
    
                Console.WriteLine("--------------");
    
    
                Array.Sort(students);
    
    
                for (int i = 0; i < studentCount; i++)
                {
                    Console.WriteLine(students[i]);
                }
    
    
                // Wait before closing
                Console.ReadKey();
    


  • marimari Member

    I know nobody is still reading these post, but here is my submission


    using System;


    namespace my_awful_program

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Title = "Skynet";

                Console.ForegroundColor = ConsoleColor.Green;

                Console.WindowHeight = 40;


                int numStudents = 0;


                Console.WriteLine("How many students are in the class : ");

                numStudents = Convert.ToInt32(Console.ReadLine());


                string[] studentsName = new string[numStudents];

                

                Console.WriteLine("What are their names?");


                for (int i = 0; i < numStudents; i++)

                {

                    studentsName[i] = Console.ReadLine();

                }


                Array.Sort(studentsName);

                Console.WriteLine("---------------------------------------------------------");


                for (int i = 0; i < numStudents; i++)

                {

                    Console.Write("\n" + studentsName[i]);

                }



                Console.ReadKey();

            }

        }

    }

  • Here is mine to !




    using System;

    using System.Collections.Generic;


    namespace NOVA_PROGRAMERSKA_TRAKA

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.ForegroundColor = ConsoleColor.Green;

                

                Console.WriteLine("How many students are there? ");

                int students = Convert.ToInt32(Console.ReadLine());


                string[] Students = new string[students];


                 for (int i = 0; i < students; i++)

                {

                    Students[i] = Console.ReadLine();

                }

                Console.WriteLine("                                                     ");


                Console.WriteLine("Here there go a,b,c....");


                Array.Sort (Students);


                for (int i = 0; i < students; i++)

                {

                    Console.WriteLine(Students[i]);

                }






                Console.ReadKey();

            }

        }

    }

  • isnxsnisnxsn Member

    Hi everyone, been learning 1 video per day. Really enjoy this task, so I made little bit drama to it.

    Here is mine:


    namespace Learn_C_
    {
        class Program
        {
            static void Main(string[] args)
            {
         
    
                Console.Write("How many students in your class: ");
    
                int stuNum = Convert.ToInt32(Console.ReadLine());
    
                Console.WriteLine("\nPlease write their name!");
    
                string[] studentName = new string[stuNum];
    
                for (int i = 0; i < stuNum; i++)
                {
                    studentName[i] = Console.ReadLine();
                }
    
                Console.WriteLine("----------------");
    
                Console.WriteLine("Here is your students names in order:");
    
                Array.Sort(studentName);
    
                for (int i = 0; i < stuNum; i++)
                {
                    Console.ReadKey();
                    int rank = i + 1;
                    Console.WriteLine(rank + ". " + studentName[i]);
                }
    
                Console.WriteLine("\nWell done!");
    
    
                // Wait before closing
                Console.WriteLine("\nPress any key to exit.", Console.ForegroundColor = ConsoleColor.Red);
                Console.ReadKey ();
            }
        }
    }
    


  • using System;

    using System.Collections.Generic;


    namespace C__test

    {

        class Program

        {

            static void Main(string[] args)

            {

                //custom console

                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.Title = "Arrays";


                //declare vars

                int numberOfKids;

                int sortingNum = 1;

                //start

                Console.WriteLine("how many kids are in your class?");

                numberOfKids = Convert.ToInt32(Console.ReadLine());

                

                string[] kidsNames = new string[numberOfKids];


                Console.WriteLine("type your kids name");

                for (int i = 0; i < kidsNames.Length; i++)

                {

                    kidsNames[i] = Console.ReadLine();

                }


                Array.Sort(kidsNames);

                Console.WriteLine("----------------------------");

                for (int i = 0; i < kidsNames.Length; i++)

                {


                    Console.WriteLine(sortingNum + ". " + kidsNames[i] );

                    sortingNum++;

                }


                // wait till key enter 

                Console.ReadKey();

                

            }

        }

    }

  • I know I'm a little late but here is my code

    using System;


    namespace bsw

    {

        class Program

        {

            static void Main(string[] args)

            {

                //unnecessary code

                Console.ForegroundColor = ConsoleColor.Magenta;

                Console.Title = "I Love Brackeys!";


                //actual code

                int number;


                Console.WriteLine("How many students are in your class: ");

                number = Convert.ToInt16(Console.ReadLine());


                string[] students = new string[number];


                for (int i = 0; i < students.Length; i++)

                {

                    int place = i + 1;

                    Console.WriteLine("Enter person " + place);

                    students[i] = Console.ReadLine();

                }


                Console.WriteLine("\nThank you, Now here are the people you entered in alphabetical order:");

                Console.WriteLine("---------------------------------------------------------------------\n");


                Array.Sort(students);


                for (int i = 0; i < students.Length; i++)

                {

                    int pos = i + 1;

                    Console.WriteLine(pos + ". " + students[i]);

                }


                Console.WriteLine("Press any key to exit");

                Console.ReadKey();

                

            }

        }

    }

  • NickTheGreekNickTheGreek Member
    edited July 2021

    using System;


    namespace New_folder

    {

        class Program

        {

            static void Main(string[] args)

            {

               Console.WriteLine("How many students do U got?"); 

               int numberOFstudents = Convert.ToInt32(Console.ReadLine());


              

               string[] students = new string [numberOFstudents];


             

               Console.WriteLine("Input the names of your students");


             

               for (int i = 0; i < students.Length; i++)

               {

                 Console.WriteLine("NAME:  ");

                 students[i] = Console.ReadLine();

               }


               Array.Sort(students);


               

               Console.WriteLine("\n\nHere they are alphabetically");


               for (int i = 0; i < students.Length; i++)

               {

                   Console.WriteLine(students[i]);

               }


               Console.ReadKey();

                

            }

        }


    }

  • My original attempt didn't work. I was trying to use an "and" (&&) statement in the "While" to check that the attempts were not at "0" as when the program initially runs both roll1 and roll2 were set to start at "0" and already considered "==".

    I did next attempt the solution to just change the roll2 to just start at 1 vs 0. However I am curious if my first solution would work and I had just missed a step.

    My first attempt (didn't work):


     Random numberGen = new Random();

                  int roll1 = 0;

                  int roll2 = 0;

                  int attempts = 0;

                Console.WriteLine("Press enter to roll the dice.");


                while(roll1 != roll2 && attempts >= 1)

                 {

                    Console.ReadKey();

                    roll1 = numberGen.Next(1, 7);

                    roll2 = numberGen.Next(1, 7);

                    Console.WriteLine("die 1: " + roll1);

                    Console.WriteLine("die 2: " + roll2);

                    Console.WriteLine(" ");

                    attempts++;

                }

                Console.WriteLine("It took you " + attempts + " attempts to roll doubles.");


                //wait

                Console.ReadKey();

            }

        }

    }

  • MD_AshifMD_Ashif Member
    edited October 2021

    Check This

    using System;


    namespace Again

    {

      class Program

      {

        static void Main(string[] args)

        {

          int totalnum;


          Console.Write("Enter the num of students: ");

          totalnum = Convert.ToInt32( Console.ReadLine());


          string[] names = new string[totalnum];


          Console.WriteLine("Enter the students name.");


          for (int i = 0; i < totalnum; i++)

          {

            names[i] = Console.ReadLine();

          }


          Console.WriteLine("\nHere they are alphabetically");


          Array.Sort(names);


          for (int i = 0; i < totalnum; i++)

          {

            Console.WriteLine(names[i]);

          }

        

           

           //To End

          Console.ReadKey();


        }

      }

    }

  • My solution to Challenge5-


    using System;


    namespace yeet_le_program

    {

        class Challenge5

        {

            static void Main(string[] args)

            {

                Console.Write("How many students are there in your class: ");

                int students = Convert.ToInt32(Console.ReadLine());


                string[] classA = new string[students];

                Console.WriteLine("Enter names: ");


                for (int i = 0; i < classA.Length; i++)

                {

                    classA[i] = Console.ReadLine();                

                }


                Console.WriteLine("----------------------- \nArranged alphabetically:");

                Array.Sort(classA);


                for (int i = 0; i < classA.Length; i++)

                {

                    Console.WriteLine(classA[i]);

                }



                Console.ReadKey();

                   

            }

        }

    }

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    
    
    namespace MyApp // Note: actual namespace depends on the project name.
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                // Title
                Console.Title = "Number of students in class";
    
    
                // Declaring variable: Number of students
                int students;
    
    
                // User input
                Console.Write("How many students are in your class: ");
                students = Convert.ToInt32(Console.ReadLine());
    
    
                // Empty array
                string[] names = new string[students];
    
    
                // User input
                Console.WriteLine("Please input the name of your students: ");
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = Console.ReadLine();
                }
    
    
                // Sorting in alphabetical order
                Console.WriteLine("\nHere are the names of your students in alphabetical order: ");
                Array.Sort(names);
                for (int i = 0; i < names.Length; i++)
                {
                    Console.WriteLine((i + 1) + ". " + names[i]);
                }
    
    
                // Wait for input before closing
                Console.ReadKey();
            }
        }
    }
    
  • VeljaVelja Member
    edited December 2021

    Found an easy solution to printing out sorted students again. Without using for loop! 😄

    using System;


    namespace My_Awesome_Program

    {

        class Program

        {

            static void Main(string[] args)

            {

                //Lists


                Console.WriteLine("How many students are in your class?");


                int number = Convert.ToInt32(Console.ReadLine());

               

                string[] students = new string[number];


                Console.WriteLine("Please input their names: ");


                for (int i = 0; i < number; i++)

                {

                    students[i] = Console.ReadLine();

                }


                Array.Sort(students);

                students.ToList().ForEach(i => Console.WriteLine(i.ToString()));


                Console.ReadKey();

            }

        }

    }

  • <code> namespace Code_Relearn_Camp

    {

        class Program

        {

            static void Main(string[] args)

            {


                Console.Write("How many students do you have: ");

               int x = Convert.ToInt32(Console.ReadLine());

               

                string[] students = new string[x];


                Console.WriteLine("Type in their names: ");


                for (int i = 0; i < students.Length; i++)

                {

                    students[i] = Console.ReadLine();

                }


                Console.WriteLine("Here they are alphabetically by first name: ");


                Array.Sort(students);


                for (int i = 0; i < students.Length; i++)

                {

                    Console.WriteLine(students[i]);

                }


                //To stop it closing before we press a key.

                Console.ReadKey();        

           

            }

        }

    } <code>

  • `namespace Code_Relearn_Camp

    {

        class Program

        {

            static void Main(string[] args)

            {


                Console.Write("How many students do you have: ");

               int x = Convert.ToInt32(Console.ReadLine());

               

                string[] students = new string[x];


                Console.WriteLine("Type in their names: ");


                for (int i = 0; i < students.Length; i++)

                {

                    students[i] = Console.ReadLine();

                }


                Console.WriteLine("Here they are alphabetically by first name: ");


                Array.Sort(students);


                for (int i = 0; i < students.Length; i++)

                {

                    Console.WriteLine(students[i]);

                }


                //To stop it closing before we press a key.

                Console.ReadKey();        

           

            }

        }

    }`

  • Here's mine


    using System;



    namespace Teachers_students

    {

        class Program

        {

            static void Main(string[] args)

            {

                Console.Title = "Class 6B";


                int studentcount;


                Console.Write("Students in class: ");

                studentcount = Convert.ToInt32( Console.ReadLine() );


                Console.WriteLine("Input the name of the students: ");

                string[] studentsname = new string [studentcount];

                for (int i = 0; i < studentcount; i++)

                {

                    studentsname[i] = Console.ReadLine();

                }


                Console.WriteLine("----------------");


                Array.Sort(studentsname);


                for (int i = 0; i < studentcount; i++)

                {

                    Console.WriteLine(studentsname[i]);

                }



                Console.ReadKey();

            }

        }

    }

  • ZothZoth Member
    edited January 12

    I found it quite fun actually. I like these where in the end of the "chapter" you're given something to do. Feels like I learn more that way :D


    I did it with a list rather than with a array. so I could specify the amount of students instead of a fixed amount and I thought about adding remove from list. It works, but not flawlessly. Throws me an error when I've removed students.





        List<string> students = new List<string>();


        Console.Write("How many students are there in your class?: ");


        int studentsCount = Convert.ToInt32(Console.ReadLine());


        Console.WriteLine(studentsCount);







      for(int i = 0; i < studentsCount; i++)

      {


         students.Add(Console.ReadLine());


      }


        students.Sort();

        Console.WriteLine("--------------------------------------");


      for(int i = 0;i < studentsCount; i++)

      {


        Console.WriteLine(students[i]);

      }

        Console.WriteLine("--------------------------------------");


        Console.Write("How many students finished school?: ");


        int studentEnd = Convert.ToInt32(Console.ReadLine());  


        Console.WriteLine("Tell us which students have ended their year: ");



       for(int j = 0; j < studentEnd; j++)

       {

        students.Remove(Console.ReadLine());

       }


        Console.WriteLine("These students has finished their year: ");

        Console.WriteLine("\n----------------------------");


      for(int k = 0; k < studentEnd; k++)

      {

        Console.WriteLine(students[k]);

       

      }




        Console.ReadKey();

Sign In or Register to comment.