User input accepted whether they input uppercase OR lowercase in C++ -


absolute beginner here (first post) , finished assignment have had create program lets user create employee wages slip , displays them searching surname, forename, employee number, etc.

i having problem if create record nancy davidson e.g. can output record if search nancy or davidson. if search nancy or davidson doesn't find it.

i using struct store each employee details, writing them data file reading file display record.

is there way can record still display if search nancy?

this code search surname function:

    //record search employee surname void searchsurname(employee data[], int row) {     string surname, again;     double wholetot=0, wholenet=0;     again = "y";      while (again=="y"||again=="y")     {         row=0;         bool found = false;         clrscr();         cout << "please enter employee surname : ";         input(surname);         clrscr();         cout << "surname search results " << surname << ". \n\n\n";         readfile (data, row);         int stop=row;         ( row = 0; row < (stop) ; row++ )             if (surname == data[row].surname)             {                 deconvertdate(data[row].date);                 cout << "   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl                      << "   # employee number - " << right(19,2) << data[row].empnum << " #" << endl                      << "   # employee surname - " << right(18,2) << data[row].surname << " #" << endl                      << "   # employee forename - " << right(17,2) << data[row].forename << " #" << endl                      << "   # department number - " << right(17,2) << data[row].dept << " #" << endl                      << "   # normal hours worked - " << right(15,2) << data[row].hours << " #" << endl                      << "   # overtime hours worked - " << right(13,2) << data[row].ohours << " #" << endl                      << "   # pay rate - " << right(26,2) << data[row].rate << " #" << endl                     << "   # gross pay - " << right(25,2) << data[row].grosspay << " #" << endl                     << "   # tax - " << right(31,2) << data[row].tax << " #" << endl                     << "   # national insurance - " << right(16,2) << data[row].natin << " #" << endl                     << "   # total deductions - " << right(18,2) << data[row].totaldeduct << " #" << endl                     << "   # net pay - " << right(27,2) << data[row].net << " #" << endl                     << "   # week ending - " << right(23,2) << data[row].date << " #" << endl                      << "   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl << endl << endl;                 wholetot+=data[row].grosspay;                 wholenet+=data[row].net;                  cout << "the total recorded gross pay of " << data[row].surname << " :" << wholetot << endl;                 cout << " , total recorded net pay :" << wholenet << endl << endl;                  found = true;             }             else                 if (found = false)                 {                     cout << "no results found surname!" << endl;                 } 

when call std::equal comparison, can give fourth argument comparitor. write comparator case insensitive comparison:

struct caseinsensitivecmp {     bool operator()( char lhs, char rhs ) const     {         return ::tolower( static_cast<unsigned char>( lhs ) )             == ::tolower( static_cast<unsigned char>( rhs ) );     } }; 

(this uses 1 argument tolower function in <ctype.h>, simplest solution beginner. in production code, of course, you'd use std::ctype facet in
<locale>.)


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -