Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7867609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:45:09+00:00 2026-06-03T00:45:09+00:00

I am having a problem with my school project. I am writing it using

  • 0

I am having a problem with my school project. I am writing it using VIM in UNIX on the school server. When I go to insert a record in my project, Last name gets skipped. First and last name are prompted simultaneously without waiting for Last Name to receive it’s input. See below:

my menu is doing this:

MENU
(I)nsert new record
(L)ast name search
(S)ave database to a file
(R)ead database from a file
(Q)uit

Enter choice: i

Insert new record selected

Please enter employee’s Last Name:
Please enter employee’s First Name:

It is skipping ahead of Last Name!

Do I need to add cout.flush() somewhere? When I add cout.flush() right under the last name section I get this error:

unixapps1:Lab1> make
g++ -o LSL lab1.cpp Employee.cpp
lab1.cpp: In function âEmployee createRecord()â:
lab1.cpp:41: error: âstruct std::istreamâ has no member named âflushâ

My menu code in my is this:

int main() {

  cout << "\n"
       << "************************************************************\n"
       << "Remember: Search for TODO's in VI before submitting project!\n"
       << "************************************************************\n\n";

  char menu_choice;
  string fileName;

  // Create a database
  LinkedSortedList<Employee> database;

  while (true) {
    // Display menu
    cout << "MENU\n"
     << "(I)nsert new record\n"
     << "(L)ast name search\n"
     << "(S)ave database to a file\n"
     << "(R)ead database from a file\n"
     << "(Q)uit\n\n";

    cout << "Enter choice: ";
    cin >> menu_choice;
    cout << endl;

    switch (toupper(menu_choice)) {

    case 'I':
      cout << "Insert new record selected\n\n";
      {database.insert(createRecord());}
      break;

    case 'L':
      cout << "Last name search selected\n\n";
      // TODO call function to search by last name
      // TODO call search for Last Name
      // TODO Print all matches found
      {string searchVal = "";
    database.find(searchVal);}
      break;

    case 'S':
      cout << "Save database to a file selected\n\n";
      // TODO call function to save database to file
      // File I/O Save to file
      cout << "Please enter a file name: " << endl;
      cin >> fileName;
      {char* file = (char*) fileName.c_str();
    writeFile(file, database);}
      break;

    case 'R':
      cout << "Read database from a file selected\n\n";
      // TODOOA call function to read database from file
      // File I/O Read file
      cout << "Please enter a file name: " << endl;
      cin >> fileName;
      {char* file = (char*) fileName.c_str();
    readFile(file, database);}
      break;

    case 'Q':
      exit(EXIT_SUCCESS);

      // default case:
    default:
      cout << "Invalid choice!\n\n"
       << "##### Please try again #####\n\n";
      break;

      cin >> menu_choice;
    }
  }
  return 0;
}

Here is my createRecord() function:

// Create the record to be inserted into the employee database
Employee createRecord() {
  // Temporary variables for getting input from user
  string stringInput = "";
  int intInput = 0;

  Employee newEmployee;

  cout << "Please enter employee's Last Name: " << endl;
  getline(cin, stringInput);
  newEmployee.setLastName(stringInput);

  cout << "Please enter employee's First Name: " << endl;
  getline(cin, stringInput);
  newEmployee.setFirstName(stringInput);

  cout << "Please enter employee's ID: ";
  getline(cin, stringInput);
  stringstream myStream(stringInput);
  myStream >> intInput;
  newEmployee.setId(intInput);

  cout << "Please enter employee's Salary: ";
  getline(cin, stringInput);
  myStream >> intInput;
  newEmployee.setSalary(intInput);

  cout << "Please enter employee's Department: ";
  getline(cin, stringInput);
  newEmployee.setDepartment(stringInput);

  cout << "Please enter employee's Phone Number: ";
  getline(cin, stringInput);
  newEmployee.setPhoneNumber(stringInput);

  cout << "Please enter employee's Address: ";
  getline(cin, stringInput);
  newEmployee.setAddress(stringInput);

  cout << "Please enter employee's Hire Date: ";
  getline(cin, stringInput);
  newEmployee.setHireDate(stringInput);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:45:10+00:00Added an answer on June 3, 2026 at 12:45 am

    Looks like there is still a newline or parts thereof in the input stream.

    Try using std::istream::ignore() to eat the remaining characters in the input stream.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goodmorning everybody, I'm having a little problem with a project for school. We are
I am having problem in getting reference of Ajax control extender using $find() or
I'm having problem restricting a query in mdx, using except function at where clause.
I am having problem getting my tooltip to work when using the jQuery load()
I'm recently started working on a school project using IntelliJ IDEA to develop an
I'm having this problem using the knockout.mapping plugin in conjunction with RequireJS. Basically, the
I am working on a school project in C++ and am using our schools
I'm writing a real-time operating system for a course in school. I'm having a
Im having problem with single value inserts. Using pyodbc LL= [] .... sqla =
I'm writing a program for a school project that is supposed to emulate the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.