-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToDo_List.go
65 lines (57 loc) · 1.3 KB
/
ToDo_List.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//Write a program to create a To-Do List
package main
import (
"bufio"
"fmt"
"os"
)
type Task struct {
Text string
Complete bool
}
func main() {
tasks := make([]Task, 0)
for {
fmt.Println("Todo List Application")
fmt.Println("1. Add Task")
fmt.Println("2. Mark Task as Complete")
fmt.Println("3. List Tasks")
fmt.Println("4. Exit")
fmt.Print("Select an option: ")
var choice int
fmt.Scanln(&choice)
switch choice {
case 1:
fmt.Print("Enter task description: ")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
taskText := scanner.Text()
tasks = append(tasks, Task{Text: taskText, Complete: false})
fmt.Println("Task added.")
case 2:
fmt.Print("Enter task number to mark as complete: ")
var taskNumber int
fmt.Scanln(&taskNumber)
if taskNumber >= 1 && taskNumber <= len(tasks) {
tasks[taskNumber-1].Complete = true
fmt.Println("Task marked as complete.")
} else {
fmt.Println("Invalid task number.")
}
case 3:
fmt.Println("Tasks:")
for i, task := range tasks {
status := " "
if task.Complete {
status = "✓"
}
fmt.Printf("%d. [%s] %s\n", i+1, status, task.Text)
}
case 4:
fmt.Println("Goodbye!")
return
default:
fmt.Println("Invalid choice. Please select a valid option.")
}
}
}