Win a copy of Java Challengers this week in the Java in General forum!

Nav Faz

Greenhorn
+ Follow
since Apr 01, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nav Faz

Hi there, I am new to this forum and was referred to here by a kind redditor so I decided to come here to ask my question, basically, I was trying to make a to-do list console app using Java C#, however, while trying to use a string variable in a switch statement, I ran into error CS0165 which states that I am using an unassigned local variable. What does this error mean and how do I fix it?
PS: Here's the code from the program I was trying to write, I ran into an error at around the last line, would really appreciate any help or advice asap
class Program
   {
       static void Main(string[] args)
       {

           //booleans to be used

           bool newtask;
           bool completetask;
           bool motivateme;
           bool addquote;
           bool incompletedtasklist;
           bool incompletedtasknum;
           bool completedtasklist;
           bool completedtasknum;
           bool help;
           bool oops;





           //all variables to be used

           Int32 IncompletedTaskNum;
           Int32 CompletedTaskNum;
           string IncompletedTaskNames;
           string CompletedTaskNames;
           string MotivationalQuotes;
           string OopsQuotes;
           string CommandName;
           string NewTask = "newtask";

       


           //procedures for program

           Console.WriteLine("Hello User, what would you like to do today?");

           CommandName = Console.ReadLine();

           //if (CommandName == "newtask")
           //{
               //newtask = true;
           //}

           switch(CommandName)
           {
               
               case "newtask":
                   newtask = true;
                   Console.WriteLine("Please enter the name of this task.");
                   IncompletedTaskNames = Console.ReadLine();
                   break;
               case "completetask":
                   completetask = true;
                   Console.WriteLine("Please enter the name of the task that you have completed.");
                   CompletedTaskNames = Console.ReadLine();
                   break;
               case "motivateme":
                   motivateme = true;
                   Console.WriteLine("You can do it!");
                   Console.ReadLine();
                   break;
               case "addquote":
                   addquote = true;
                   Console.WriteLine("Please enter the quote that you would like to add.");
                   MotivationalQuotes = Console.ReadLine();
                   break;
               case "incompletedtasklist":
                   incompletedtasklist = true;
                   Console.WriteLine(IncompletedTaskNames);
                   break;






           }


       }





   }      


       
   }
1 month ago