I wrote code that takes tasks from the user in store in the array, here is the code.
#include <iostream>
#include <string>
#include <conio.h>
#include <vector>
using namespace std;
//Globle variables
int Counter = 0 ;
vector<string> tasksList;
string task;
//function
void AddingTasks(){ // the problme is here
cout<<"type your task here: ";
cin>>task;
tasksList.push_back(task);
cout<<tasksList[tasksList.size()-1]<<" added "<<endl;
//the console:
// I type for example
//type your task here: Buy electrician piano today.
// you see the 'space' after 'buy' word and the first letter of 'electrician' the letter 'E' the problem is about that
}
int main(int argc, char const *argv[])
{
tasksList.resize(Counter);
char FuncationChoose;
bool exit ;
do // while do for repeating the code
{
cout<<"Mustafa ToDoList the best to do list ever! "<<endl;
cout<<"Choose: [1] add task [2] view tasks [3] edit task [4] delete task [E] Exit : ";
cin>>FuncationChoose;
if (FuncationChoose== '1')
{
AddingTasks();
exit =false;
}
if (toupper(FuncationChoose) == 'E')
{
exit = true;
}else{
cout<<"error!."<<endl;
exit = true;
}
} while ( exit == false );
system("pause");
return 0;
}
When I enter tasks with space and the word that begins with the letters of the list for example the letter 'E' it exit the code because 'E' for exiting the program, the user input in 'AddingTasks' affect the whole code.