Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Simple Console Application Enumeration Issues

I am new to C# and need some help on the below code.

This console application is supposed to store details of 5 applicants in 5 different corresponding arrays. Finally this should allow me to view the names of the applicants by means of the menu I have created after declaring my arrays. Please note that the program is not yet complete.

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

  namespace ConsoleApplication1
 {
 enum Qualifying {Diploma=1, Bachelor=2, Degree=3, Masters_Degree=4, PhD=5};
 class Program
 {
    static void Main(string[] args)
    {
        string[] ids = new string[5];
        string[] names = new string[5];
        string[] dobs = new string[5];
        string[] yoe = new string[5];
        string[] loq = new string[5];

        bool x = true;
        while (x)
        {
            Console.WriteLine("Please choose an option");
            Console.WriteLine("1.Add Applicants Details");
            Console.WriteLine("2.Display Applicants names");
            Console.WriteLine("3.Search for Applicant details");
            Console.WriteLine("4.Modify Applicant details");
            Console.WriteLine("5.Exit");
            int choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
                case 1:
                    {
                        Console.WriteLine("Please fill in the following: ");
                        for (int i = 0; i < ids.Length; i++)
                        {
                            Console.WriteLine("Enter 5 ID Card noS");
                            string id = Console.ReadLine();

                            ids[i] = id;
                        }

                        for (int i = 0; i < names.Length; i++)
                        {
                            Console.WriteLine("Enter 5 Full Names");
                            string name = Console.ReadLine();

                            names[i] = name;
                        }

                        for (int i = 0; i < dobs.Length; i++)
                        {
                            Console.WriteLine("enter 5 Date of births");
                            string dob = Console.ReadLine();

                            dobs[i] = dob;
                        }

                        for (int i = 0; i < yoe.Length; i++)
                        {
                            Console.WriteLine("Enter 5 Years of experience");
                            string years = Console.ReadLine();

                            yoe[i] = years;
                        }

                            Console.WriteLine("Enter 5 Levels of Qualification, Choose from the list and press the number according to the qualification held:\n1=Diploma, 2=Bachelor, 3=Degree, 4=Masters Degree, 5=PhD");

                            for(int i=0; i<5; i++)
                            {
                                int num=Convert.ToInt32(Console.ReadLine());                              
                                {
                                if (num <= 4)
                                {
                                    loq[i] = (Qualifying)num;
                                }
                                else
                                    Console.WriteLine("Invalid input");
                                }
                            }
                        break;
                    }
                case 2:
                    {
                        for (int i = 0; i < names.Length; i++)
                        {
                            Console.WriteLine("The names of the students are " + names[i]);
                        }
                        break;
                    }
                case 3:
                    {
                        Console.WriteLine("Please enter the name of the applicant who you like to edit");
                    }
                    break;
                case 4:
                    {
                        Console.WriteLine("Input the applicants ID NUMBER for modification: ");
                        string id1 = Console.ReadLine();

                        //if (id1 == id)
                        //    Console.WriteLine("Full Name");
                        string name1 = Console.ReadLine();
                        Console.WriteLine("Date of birth");
                        string dob1 = Console.ReadLine();
                        Console.WriteLine("Years of experience");
                        int years1 = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Levels of Qualification, Choose from the list:\nDiploma, Bachelor, Degree, Master Degree, PhD");
                        string quals1 = Console.ReadLine();
                        break;
                    }

                case 5:
                    {
                        Console.WriteLine("You chose to quit. BYE =D");

                        x = false;
                        break;
                    }
            }
        }
    }
}
}

I have an error in line 78 stating:

"Cannot implicitly convert type 'ConsoleApplication1.Qualifying' to 'string'"

Can anyone please provide any suggestions in order to fix this issue.

Thank you.

Luke

like image 997
LukeBorg Avatar asked Feb 09 '26 21:02

LukeBorg


1 Answers

loq[i] = (Qualifying)num;

should be

loq[i] = ((Qualifying)num).ToString();

loq stores a string type and you're trying to put in an enum of Qualifying.

like image 68
keyboardP Avatar answered Feb 16 '26 17:02

keyboardP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!