dictionary - C++ map, switch, and main menu trouble -


when run main menu, able add data needed map, problem happens when go menu , find when try print data nothing appears. in case wondering, there no errors, not print data stored within map when run print contacts menu. below code.

main

#include <iostream> using namespace std; #include "addcontact.h"   //password "delta" use upper case d , rest lower case int main() {     addcontact con;     con.menu();      return 0; } 

addcontact.h

#include <iostream> #include<cstdlib> #include<map> using namespace std;  #ifndef addcontact_h_ #define addcontact_h_  class addcontact { public:     std::map<int, addcontact> people; private:     string contactname;     long long contactphone;     string address;     string email;     string skype;  public:     addcontact();     addcontact(string contactname, long long contactphone, string address, string email, string skype);     void add();     void print()const;     void view();     void menu();     void password(); };  #endif /* addcontact_h_ */ 

addcontact.cpp

#include "addcontact.h" addcontact::addcontact(): contactname(""), contactphone(0), address(""), email(""), skype(""){  } addcontact::addcontact(string contactname, long long contactphone, string address, string email, string skype) {     this->contactname = contactname;     this->contactphone = contactphone;     this->address = address;     this->email = email;     this->skype = skype; } void  addcontact::password(){     cout << "please enter password. " << endl;         string pass;         cin >> pass;         if (pass != "delta") {             password();         } } void  addcontact::menu(){      cout << "!!mycircle contact!!" << endl;     cout << endl;     password();     int selection;     {         cout << "***************************" << endl;         cout << "1. add new contact         " << endl;         cout << "2. display contact      " << endl;         cout << "3. quit                    " << endl;         cout << "***************************" << endl;         cin>> selection;         switch(selection){         case 1:             add();             break;             view();             break;         }     } while (selection != 0);    } void addcontact::add() {     (int = 0; < 1; i++) {         string temp1;         cout << "please enter contact name: " << endl;         cin >> temp1;         long long temp2;         cout << "please enter contact phone number: " << endl;         cin >> temp2;         int choice;         cout<< "press 1 if add additional contact info or press 0 return main menu "<< endl;         cin >> choice;         if (choice == 1) {             string temp3 = "";             cout << "please enter contact address: " << endl;             cin>> temp3;             getline(cin, temp3);             string temp4= "";             cout << "please enter contact email: " << endl;             cin >> temp4;             string temp5 = "";             cout << "please enter contact skype: " << endl;             cin >> temp5;             people[i] = addcontact(temp1, temp2, temp3, temp4, temp5);     } else {      } } } void addcontact::print()const{     cout<<contactname<<" "<<contactphone<<" "<<address<<" "<<email<<" "<<skype<<endl; } void addcontact::view(){     for(map<int, addcontact>::iterator = people.begin(); != people.end();it++){              it->second.print();         } } 

it looks you're mising default in switch statement:

switch(selection){     case 1:         add();         break;         view();         break; } 

is mean be

switch(selection){     case 1:         add();         break;     default:         view();         break; } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -