Guest User

C++ errors

a guest
Sep 17th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. void addItem(vector<string> &list, string &text);
  8. void removeItem(vector<string> &list, int size, int &position);
  9. void updateItem(vector<string> &list, int size, int &item);
  10. void showItems(vector<string> list, int size);
  11. void printActionList();
  12.  
  13.  
  14. int main()
  15. {
  16. int action = 0;
  17. string name;
  18. vector<string> list;
  19. int list_size = list.size();
  20. bool running = true;
  21. int position = 0;
  22.  
  23. cout << "Enter your name: ";
  24. cin >> name;
  25.  
  26. cout << "Welcome " << name << "!\n";
  27.  
  28. while (running)
  29. {
  30. string text;
  31. printActionList();
  32.  
  33. cout << "Enter action: ";
  34. cin >> action;
  35.  
  36. switch (action)
  37. {
  38. case 1:
  39. showItems(list, list_size);
  40. continue;
  41. case 2:
  42. cout << "Enter text: ";
  43. cin >> text;
  44. addItem(list, text);
  45. text = "";
  46. case 3:
  47. cout << "Enter position to remove an item: ";
  48. cin >> position;
  49. removeItem(list, list_size, position);
  50. position = 0;
  51. case 4:
  52. cout << "Enter position to remove an item: ";
  53. cin >> position;
  54. updateItem(list, list_size, position);
  55. position = 0;
  56. case 5:
  57. running = false;
  58. }
  59.  
  60. }
  61.  
  62. cout << "Goodbye " << name << "!\n";
  63.  
  64. return 0;
  65. }
  66.  
  67. void printActionList()
  68. {
  69. cout << "------ ToDo-List manager ------\n\n";
  70. cout << "1. Show list\n";
  71. cout << "2. Add list\n";
  72. cout << "3. Remove list\n";
  73. cout << "4. Update list\n";
  74. cout << "5. Exit\n";
  75. cout << "-------------------------------\n\n";
  76. }
  77.  
  78. void showItems(vector<string> list, int size)
  79. {
  80. for (int i = 0; i < size; i++)
  81. {
  82. cout << i << ". " << list[i];
  83. }
  84.  
  85. cout << '\n';
  86. }
  87.  
  88. void addItem(vector<string> &list, string &text)
  89. {
  90. list.push_back(text);
  91. }
  92.  
  93. void removeItem(vector<string> &list, int size, int &position)
  94. {
  95. list.erase(list.begin() + position);
  96. }
  97.  
  98. void updateItem(vector<string> &list, int size, int &item)
  99. {
  100. string place_text;
  101. for (int i = 0; i < size; i++)
  102. {
  103. if (i == item)
  104. {
  105. printf("Position: %d", i);
  106. cout << "Enter text: ";
  107. getline(cin >> ws, place_text);
  108. list[i] = place_text;
  109. break;
  110. }
  111. else
  112. {
  113. cout << "Item not found in the list";
  114. break;
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment