Menu
Coddy logo textTech

Adding a Task

Part of the Logic & Flow section of Coddy's C++ journey — lesson 19 of 56.

challenge icon

Challenge

Easy

Extend your task list tool by implementing the functionality to add new tasks to the system. This builds on the previous lesson's foundation by adding user interaction and task storage capabilities.

The following input will be provided:

  • A string representing the task description to add to the list

Your program should:

  1. Start with the same setup from the previous lesson (empty std::vector<std::string> named tasks and welcome message)
  2. Read a task description from the input
  3. Use push_back() to add the task description to the tasks vector
  4. Print a confirmation message showing that the task was successfully added
  5. Display the current number of tasks in the list using the vector's .size() method

Use the following exact output format:

Welcome to Task List Tool!

Menu Options:
1. Add Task
2. View Tasks
3. Quit

Task list system initialized and ready!
Task "[task description]" added successfully!
Total tasks: [number of tasks]

This exercise demonstrates how vectors can dynamically grow as you add elements, and how the .size() method reflects the current number of stored items. The confirmation message provides user feedback that the operation completed successfully.

Try it yourself

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    vector<string> tasks;
    
    cout << "Welcome to Task List Tool!" << endl;
    cout << endl;
    cout << "Menu Options:" << endl;
    cout << "1. Add Task" << endl;
    cout << "2. View Tasks" << endl;
    cout << "3. Quit" << endl;
    cout << endl;
    cout << "Task list system initialized and ready!" << endl;
    
    return 0;
}

All lessons in Logic & Flow