Help! What's wrong with my code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help! What's wrong with my code?

The ListPriorities(index) doesn't output the correct priority level. I'm so confused on what to do. HELP https://sololearn.com/compiler-playground/cVEgBJdfCEJ7/?ref=app

10th Apr 2024, 1:22 PM
Meyls
Meyls - avatar
13 Answers
+ 1
Try this.. using System; using System.Collections.Generic; namespace Sololearn { class Program { static List<string> notes = new List<string>(); static List<string> Priorities = new List<string> { "URGENT", "IMPORTANT", "Chill" }; static void Main(string[] args) { SetTaskPriority(); Console.ReadKey(); } static void SetTaskPriority() { if (notes.Count == 0) { Console.WriteLine("\nNo Tasks Available. Cannot Set Task Priority."); Console.WriteLine("Press any key to continue."); Console.ReadKey(); return; } Console.WriteLine("\nTASKS: "); for (int i = 0; i < notes.Count; i++) { Console.WriteLine(
quot;{i + 1}. {notes[i]}"); } Console.Write("\nEnter the number of the task to set priority: "); if (int.TryParse(Console.ReadLine(), out int inde
12th Apr 2024, 3:09 AM
Suhani Kewat
Suhani Kewat - avatar
0
Can you please create a brief User Document that describes how to use your program and what the expected behaviors are? This will help with testing and debugging.
10th Apr 2024, 2:19 PM
Sam
0
I don't know how to create a User Document, so I'll just paste this here. I have a minor issue with my code. Apparently, this code here is just a snippet of the whole program I need to run. I am currently making a console application that is similar to a to-do list app and one of its main features is a Task Priority feature wherein the user can assign task priority level to each task inputted in the console. However, I encountered a not-so-minor issue that I've been debugging my whole life(lol. srsly tho I've been working on this since last night and it just keeps getting worse. I'm new to programming by the way). So I decided to ask for help here hoping a good Samaritan will help me figure out the solution to my dilemma. So the problem is every time I assign a priority level to a task (assuming that I'm the user), the ListPriorities method doesn't input the correct priority level (URGENT, IMPORTANT, Chill). Ps. I have no problem with the other features. Just this one.
10th Apr 2024, 4:05 PM
Meyls
Meyls - avatar
0
Meyls walk me through the process of providing input to your program. How would you tell a new user to run this snippet and what would the expected output be?
11th Apr 2024, 12:55 AM
Sam
0
First, if the user goes to Task Priority feature and there's no task available (notes.Count ==0), the program shall output "No Tasks Available. Cannot Set Tasks Priority). To solve this, the user needs to input a task first (there's a separate feature for this). After inputting one or multiple tasks(it doesn't really matter how many), the user can now enter priority levels for their tasks in the Task Priority menu. The program shall output the list of tasks entered by the user, then ask the user to enter the number of the task to set priority. If the user input an invalid index (ex: there are only two tasks but the user input 3, it will be invalid), the program shall print out "Invalid" and shall again ask the user the same question until a valid index is entered, otherwise it will continue to the Select(index) method and ask the user to enter the priority level through numbers (1 is URGENT, 2 is IMPORTANT, 3 is Chill, & 0 is Cancel),
11th Apr 2024, 3:06 AM
Meyls
Meyls - avatar
0
if the user input a number not in the choices, it will likely be invalid, this will repeat again and again till the user enter the valid index. It will then print out "{taskname} priority set to {prioritylevel} (for example: 'Eat' priority set to URGENT). It will then go to the ListPriorities(int index) method and output the list of tasks along with its priority levels. Like this: Tasks With Priority: "\nTask: {taskname}, Priority: {prioritylevel}. But I have an error here because the priority level it outputs doesn't match the priority level selected in the Select(index) method. For ex: instead of "Task: Eat, Priority: URGENT", it will output "Task : Eat, Priority: IMPORTANT". Sam
11th Apr 2024, 3:06 AM
Meyls
Meyls - avatar
0
Meyls I did a brief test and so far my results are: Initial run with input "foo 1" throws an error for a missing "}". I placed one at the end of the file. Used input "foo 1" again and now I'm receiving errors that "Priorities" isn't defined.
11th Apr 2024, 2:57 PM
Sam
0
Sam my bad I forgot to put static List<string> notes = new List<string>(); and static List<string> Priorities = new List<string> {"URGENT", "IMPORTANT", "Chill"}; in the class Program
11th Apr 2024, 4:58 PM
Meyls
Meyls - avatar
0
Meyls You have two main functions; remove one. You have two "notes" declared; remove the second.
12th Apr 2024, 3:06 AM
Sam
0
Explain that in a shortcut way.
12th Apr 2024, 9:02 AM
Xavier Borgoyary Basumatary
Xavier Borgoyary Basumatary - avatar
0
Hgjhg
12th Apr 2024, 11:27 AM
Cert Test
0
Meyls enum is a better choice than List<string> for priority data type. This way we can be sure no weird things are added to it later on. Also, I created a custom struct for prioritized task . Then it is easier to just access and modify a List of that. https://sololearn.com/compiler-playground/c9h2YRGZ7ANm/?ref=app
13th Apr 2024, 7:20 AM
Bob_Li
Bob_Li - avatar
0
Thank you for the help, everyone!
14th Apr 2024, 11:26 AM
Meyls
Meyls - avatar