-3

So, will first log in, then I will chose Employees, but it always gives me payroll. I don't know if I messed up code-wise or it's just the stupid Online IDE I'm using. Well, here it is...


#include <iostream>
#include <string>
#ifndef en
#define en std::endl
#endif

using namespace std;

void login() {
    //Basic login program
    string correctPass = "Love";
    string attemptPass;
    cout << "Please insert password" << en;
    cin >> attemptPass;
    if (attemptPass == correctPass) {
        cout << "Access Granted" << en << en;
    } else {
        login();
    }
}

void mainMenu() {
    void employees();
    void payroll();
    cout << en << "MAIN MENU" << en << en << "Payroll" << en << "Employees" << en << en;
    string mainMenuOption;
    cin >> mainMenuOption;
    if (mainMenuOption == "Payroll" || "payroll") {
    payroll(); }
    else if (mainMenuOption == "Employees" || "employees") {
    employees(); }
    else {
    mainMenu(); }
}

void payroll(){
    cout << en << "WELCOME TO PAYROLL" << en << "-----------------" << en << "fish" << en;
}

void employees(){
    cout << en << "WELCOME TO EMPLOYEES" << en << "-----------------" << en << "eleven" << en;
}

int main() {
    login();
    mainMenu();

    return 0;
}

If anyone know's how I messed up please tell! Thanks!

Michael Erickson
  • 41
  • 1
  • 1
  • 4

1 Answers1

5

As mentioned in the comments. Your comparison is not quite right.

Advice: Don't use using namespace std see why here: Why is “using namespace std” in C++ considered bad practice?. Also use \n instead of std::endl for better performance unless you really want the advantages of std::endl (like flush()).

Also your function call should not include the return type. To call payroll() you just use payroll(); and not void payroll();

This should work:

# include <iostream>
# include <string>
# ifndef en
#define en std::endl
#endif

void login()
{
    //Basic login program
    std::string correctPass = "Love";
    std::string attemptPass;

    std::cout << "Please insert password:\n";
    std::cin >> attemptPass;

    if (attemptPass == correctPass)
        std::cout << "Access Granted\n\n";
    else
        login();
}

void mainMenu()
{
    employees();
    payroll();

    std::cout << "\nMAIN MENU\n\nPayroll\nEmployees\n\n";
    std::string mainMenuOption;
    std::cin >> mainMenuOption;

    if (mainMenuOption == "Payroll" || mainMenuOption == "payroll")
        payroll();
    else if (mainMenuOption == "Employees" || mainMenuOption == "employees")
            employees();
         else
            mainMenu();
}

void payroll()
{
    std::cout << "\nWELCOME TO PAYROLL\n-----------------\nfish\n";
}

void employees()
{
    std::cout << "\nWELCOME TO EMPLOYEES\n-----------------\neleven\n";
}

int main()
{
    login();
    mainMenu();

    return 0;
}
Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104