This repository was archived by the owner on May 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.cpp
More file actions
85 lines (72 loc) · 2.46 KB
/
Copy pathtodo.cpp
File metadata and controls
85 lines (72 loc) · 2.46 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <string>
#include <vector>
struct Task {
std::string description;
bool completed;
Task(const std::string& desc) : description(desc), completed(false) {}
};
void displayTasks(const std::vector<Task>& tasks) {
if (tasks.empty()) {
std::cout << "No tasks yet!" << std::endl;
return;
}
std::cout << "\n=== My Tasks ===" << std::endl;
for (size_t i = 0; i < tasks.size(); ++i) {
std::cout << i + 1 << ". ";
if (tasks[i].completed) {
std::cout << "[X] ";
} else {
std::cout << "[ ] ";
}
std::cout << tasks[i].description << std::endl;
}
std::cout << std::endl;
}
int main() {
std::vector<Task> tasks;
std::string input;
std::cout << "Welcome to TODO List!" << std::endl;
std::cout << "Commands: add, list, complete, quit" << std::endl;
// Main loop
while (true) {
std::cout << "> ";
std::cin >> input; // Read one word
if (input == "quit") {
std::cout << "Goodbye!" << std::endl;
break; // Exit the loop
}
else if (input == "list") {
displayTasks(tasks);
}
else if (input == "add") {
// Read the rest of the line as the task description
std::string description;
std::getline(std::cin, description); // Get the rest of the line
// Remove leading space
if (!description.empty() && description[0] == ' ') {
description = description.substr(1);
}
if (!description.empty()) {
tasks.push_back(Task(description));
std::cout << "Added: " << description << std::endl;
} else {
std::cout << "Please provide a task description" << std::endl;
}
}
else if (input == "complete") {
int taskNum;
std::cin >> taskNum; // Read the task number
if (taskNum >= 1 && taskNum <= static_cast<int>(tasks.size())) {
tasks[taskNum - 1].completed = true;
std::cout << "Completed: " << tasks[taskNum - 1].description << std::endl;
} else {
std::cout << "Invalid task number!" << std::endl;
}
}
else {
std::cout << "Unknown command. Try: add, list, complete, quit" << std::endl;
}
}
return 0;
}