Fun vector project not doing what I want!!!
Really glad your guys are here. I sent this issue to my professor and he told me to worry about completing the graded assignments. However if I don't fully understand something, why move on?
Ok first of all when ever run the program it always returns the addContact() then stops. I want to it keep running so I would assume I need a while statement, which I tried in main() but it didn't work. Furthermore I do not understand why my if and ifelse statements are failing!
Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void userPrompt();
char getPrompt(char);
void accessPrompt();
void addContact();
void deleteContact();
void CountContact();
vector<string> contacts;
void userPrompt()
{
char prompt;
cout<<"Enter [a] to add a contact, [d] to delete a contact, [c] to count the contacts"<<endl;
cin >> prompt;
getPrompt(prompt);
}
char getPrompt(char prompt)
{
return prompt;
}
void accessPrompt()
{
char prompt = '\0';
char user_request = getPrompt(prompt);
if (user_request == 'a' || 'A') {
addContact();
}
else if (user_request == 'd'|| 'D')
deleteContact();
else if (user_request == 'c' || 'C')
CountContact();
}
void addContact()
{
string contact;
cout<<"Add the name of your contact below"<<endl;
getline(cin, contact);
contacts.push_back(contact);
}
void deleteContact()
{
int position;
cout<<"Where is the contect located that you want to delete?"<<endl;
cin>>position;
cin.ignore();
contacts.erase(contacts.begin() + position); //contacts.begin=0 so position will find the contact
}
void CountContact()
{
cout<<"You have"<<contacts.size()<<" contact(s)."<<endl;
for (int i=0; i<contacts.size(); i++) {
cout<<i<<"."<<contacts.at(i)<<endl; //just another way to way to write contacts[i]
}
}
int main(int argc, const char * argv[])
{
userPrompt();
accessPrompt();
return 0;
}