C
C#3w ago
sdsd

how do i add the "remove task" thing?

https://hatebin.com/qkmmhnqzmt
using System.Collections; using System.ComponentModel.Design; using System.Data.Common; using System.Diagnostics; using System.Formats.Tar; using System.Xml.Serialization; string task = null; string input; string List = null; int TaskCount = 0; string taskprevious = ""; Console.WriteLine("Welcome to the To Do List!"); while (true) { Console.WriteLine(List); Console.WriteLine("Type 'a' to add a task 'b' to remove a task 'c' to modify a task and 'd' to exit"); while (true) { input = Console.ReadLine(); if (input == "a"input == "b"input == "c"||input == "d") { break; } else { Console.WriteLine("Invalid input."); } } TextWriter tw = new StreamWriter("SavedGame.txt"); switch (input) { case "a": { TaskCount++; Console.Write($"{TaskCount}. "); task = Console.ReadLine(); Console.Clear(); Console.WriteLine("Changes applied!"); tw.WriteLine(TaskCount); tw.WriteLine($"{TaskCount}. {task}"); tw.Close(); break; } case "b": { TaskCount --; Console.WriteLine("Which Task do you want to remove? ('1' for task 1, '2'for task 2 etc..)"); while(true) { string answer = Console.ReadLine(); if(int.TryParse(answer, out int answer1)&&(answer1 <= 5)) { break; } else { Console.WriteLine("Invalid Input!"); } } break; }
} for (int i = 0;i < TaskCount;i++) {
TextWriter tw1 = new StreamWriter("SavedGame.txt"); tw1.WriteLine(List); tw1.WriteLine($"{i + 1}.{task}"); tw1.Close();
} TextReader tr1 = new StreamReader("SavedGame.txt"); List = tr1.ReadToEnd(); tr1.Close(); if (input == "d") break; }
7 Replies
HtmlCompiler
HtmlCompiler3w ago
do you have any idea on how to do this that maybe you don't know how to implement or do you need more help?
sdsd
sdsdOP3w ago
my only idea is in the for loop instead of just reading out the text file it makes a new string for new tasks each time the loop is executed and writes in the textfile so that if the user wants to remove you can just set the string to null but idk if thats even possible
HtmlCompiler
HtmlCompiler3w ago
there is a thing though if i understand correctly the tasks file is like
1.text
2.text
...
1.text
2.text
...
so if you remove say task 2 would you want to move all the numbers back of 1 or would you let them the same
sdsd
sdsdOP3w ago
move back if possible
Nasdack
Nasdack3w ago
$codegif
HtmlCompiler
HtmlCompiler3w ago
i wanted to post that but i didn't remember the tag i would suggest then copying all the todos in a new file and when the process is finished deleting the old file or you could even keep one old file as backup
Want results from more Discord servers?
Add your server