0

iam trying to display employees based on their designation like hr,developer like that i tried a code but it is not displaying output

void searchDeptReport()
{
    system("cls");
    char department[20];
    int i;
    ;
    bool found = false;
    cout << "\nYou can Search only through the designation of Employees\n\n";
    cout << "\nEnter the Department to get report : ";
    cin >> department;
    for (int i = 0; i <= num - 1; i++)
    {
        if (emp[i].designation == department)
        {
            cout << "\nName\t  Emp ID\tGender\t Designation " << endl;
            cout << "------------------------------------------------\n";
            gotoXY(0, 7);
            cout << "Name : " << emp[i].name << endl;
            gotoXY(11, 7);
            cout << "Employee Id : " << emp[i].code << endl;
            gotoXY(21, 7);
            cout << "Gender : " << emp[i].gender << endl;
            gotoXY(35, 7);
            cout << "Designation : " << emp[i].designation << endl;
            found = true;
            cout << "\n\nPress Any key for Menu..";
        }
    }

    if (!found)
    {
        cout << "\n\nNo records Found...!!!\a";
        cout << "\n\nPress Any key for Menu..";
    }
    getch();
}

enter image description here

  • Please don't post images of text, put the text in the question itself. – perivesta Sep 16 '22 at 14:22
  • `emp[i].designation == department` You don't show what `emp` is, but comparing character arrays does not work like this. I recommend you use `std::string` instead – perivesta Sep 16 '22 at 14:23
  • `if (emp[i].designation == department)` is not going to work with c-strings as it compares pointers not the contents of the string. If you can use `std::string` this type of comparison would just work. – drescherjm Sep 16 '22 at 14:39
  • 1
    Does this answer your question? [How do I properly compare strings in C?](https://stackoverflow.com/questions/8004237/how-do-i-properly-compare-strings-in-c) – drescherjm Sep 16 '22 at 14:44

0 Answers0