2

Hey I'm new to c++ and I have to make a user input the number, and whatever number that person chooses(1-5) will send them to the area that corresponds with that number. I don't really know how to do it, so can anyone show me or tell me what to do? Feel free to ask any questions. Thanks!

Code below:

cout << "1.Input New Employee"; endl;
cout << "2.Search For Employee By ID Number";  endl;
cout << "3.Edit Existing Employee Information"; endl;
cout << "4.Display all Employees"; endl;
cout << "5.EXIT";endl;

P.S: Now I get this error message"Statement cannot resolve address of overload function" can anyone tell me how to fix it? Thanks

Herbert Ortiz
  • 131
  • 1
  • 6
  • 14

3 Answers3

0

Use "cin" get the press character.

char ch;

cin >> ch;

Now ch varriable has the pressed character. You can take input of all data types using this.

Rode093
  • 396
  • 2
  • 11
  • 2
    This won't get anything until the enter key is pressed, and then anything after the first key will be left in the input buffer. I'd sooner recommend [`std::getline`](http://en.cppreference.com/w/cpp/string/basic_string/getline). – Fred Larson Nov 18 '16 at 17:09
0

use cin to take the input and then switch to call corresponding functions.

int choice;
cin>>choice;
switch(choice)
{
    case 1 : //your code;
             break;
    case 2 : //your code;
             break;
   /*  rest of your cases */
}
Karan Nagpal
  • 341
  • 2
  • 10
0

Here is a script that should help show you what you need to do:

bool loop = true;
while(loop){
    cout << "What do you want to do?\n";
    cout << "    1 - Input New Employee\n";
    cout << "    2 - Search for Employee By ID Number\n";
    cout << "    3 - Edit Existing Employee Information\n";
    cout << "    4 - Display All Employees\n";
    cout << "    5 - EXIT\n";
    cout << "Your selection: ";
    string select; getline(cin, select);
    cout << "/n";
    try {
        switch(stoi(select)){
            case 1:
                employeeInput(); // Sample code
                break;
            case 2:
                employeeIDSearch(); // Sample code
                break;
            case 3:
                employeeInfoEdit(); // Sample code
                break;
            case 4:
                employeeDisplayAll(); // Sample code
                break;
            case 5:
                loop = false; // Exit loop
                break;
            default:
                cout << "Invalid Input.\n\n";
                break;
        };
    };
    catch(const std::exception& ex){
        cout << "Invalid Input.\n\n";
    };
};

Just a side note, the endl command is meant to be piped into cout, not used as a standalone statement.

EDIT: The functions I used are simply placeholders, I wanted to show how you'd use the code in the switch. Also, feel free to use this :)

Isaac Corbrey
  • 553
  • 3
  • 20