Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- //Variables
- string names[5];
- names[0] = "Sam";
- names[1] = "Jack";
- names[2] = "Sue";
- names[3] = "Sue";
- names[4] = "Mary";
- bool keepGoing = true;
- int user;
- char answer = 'y';
- //Title
- cout << "Find the employee app" << endl << endl;
- //Traps them until they say no later
- while (keepGoing){
- //Asks users could
- cout << "Please enter the employee code ";
- cin >> user;
- //If user types correct values
- switch (user){
- case 1 : cout << " Employee Name: Sam" << endl;
- break;
- case 2 : cout << " Employee Name: Jack" << endl;
- break;
- case 3 : cout << " Employee Name: Sue" << endl;
- break;
- case 4 : cout << " Employee Name: Sue" << endl;
- break;
- case 5 : cout << " Employee Name: Mary" << endl;
- break;
- default : cout << " ***Invalid code***" << endl << endl;
- }
- //If user types in good values, this will help them escape the infinite loop. OTHERWISE IT WILL KEEP ASKING THEM FOR A CODE THANKS TO THE WHILE LOOP UP THERE
- if (user >= 1 && user <= 5){
- //YOU ARE AN IDIOT while loop. Keeps asking them over and over until they type good answers YES and NO. YES and NO are coded to let them back into the while loop or end the program.
- while (answer != 'n'){
- cout << endl << "Search again? "; //Ask user
- cin >> answer;
- //DOOR! User wants to quit by typing no
- if (answer == 'n' || answer == 'N'){
- //Breaks the keepGoing while loop, ending program
- keepGoing = false;
- cout << "Goodbye!";
- }
- //DOOR! User wants go again, sending them back into the loop by break the YOU ARE AN IDIOT while loop
- if (answer == 'Y' || answer == 'y'){
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement