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 7772005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:47:09+00:00 2026-06-01T16:47:09+00:00

Hey guys i am having an issue with an assignment I am working on.

  • 0

Hey guys i am having an issue with an assignment I am working on.

The code is as follows:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

class payroll
{
private:
    char empnum[10];
    char empfirstname[150];
    char emplastname[150];
    char empsin[9];
    char empdob[10];
    char empphone [15];
    char empstreet[100];
    char empcity[60];
    char empprovince[150];
    char empcountry[200];
    char empstatus[50];       //Employee status. EX: Terminated, On leave, Active etc.
    int empsalaryei;
    int empsalaryfedtax;
    int empsalarycpp;
    int empsalarynet;
    int empsalarygross;

public: 
    void addrec(void);
    void modrec(void);
    void viewrec(void);
    void exit(void);
};

payroll rec;
payroll emp;
ifstream inFile1;
ifstream inFile2;
bool check = false;

int main()
{
    system("CLS");
    char ch;

    do
    {
        cout<<"1. Add an employee\n";
        cout<<"2. Modify employee record\n";
        cout<<"3. View employee record\n";
        cout<<"0. Exit\n";
        cout<<"Please choose an item: ";
        if (check == true)
        {
            system("CLS");
            ch=0;
        }
        else
            cin>>ch;

        switch(ch)
        {
            case '1':
                emp.addrec();
                break;

            case '2':
                emp.modrec();
                break;

            case '3':
                emp.viewrec();
                break;

            case '0':
                emp.exit();
                return 0;
        }
    }while(ch !=0);

    return 0;

}

void open_employee_info()               //function to open employee data file
{
    string filename1 = "employee-details.dat";        //define which file to open 

    inFile1.open(filename1.c_str());  //open our payroll file
    if(inFile1.fail())                                                       //if our file open fails....
    {
        cout << "\nSorry the file was not opened successfully"<< "\n Please check that the file does exist or create it" << endl;
        exit(1);
    }
    cout << "\n The file was opened successfully" << endl;
}

void open_payroll_info()               //function to open payroll salary information file
{
    string filename2 = "payroll-info.dat";          //define file name

    inFile2.open(filename2.c_str());
    if(inFile2.fail())
    {
        cout << "\nSorry the file was not opened successfully"<< "\n Please check that the file does exist or create it" << endl;
        exit(1);
    }
    cout << "\n The file was opened successfully" << endl;
}

void payroll::addrec(void)          //Record adding
{
    char userinputadd = ' ';

    cout << "\nPlease Enter the Employee number: ";
    gets(rec.empnum);
    cout << "\nPlease Enter the Employee's First Name: ";
    gets(rec.empfirstname);
    cout << "\nPlease Enter the Employee's Last Name: ";
    gets(rec.emplastname);
    cout << "\nPlease Enter the Employee's Date of Birth (mmddyyyy): ";
    gets(rec.empdob);
    cout << "\nPlease Enter the Employee's Social Insurance Number: ";
    gets(rec.empsin);
    cout << "\nPlease Enter the Employee's Phone Number: ";
    gets(rec.empphone);
    cout << "\nPlease Enter the Employee's Address: ";
    gets(rec.empstreet);
    cout << "\nPlease Enter the Employee's City: ";
    gets(rec.empcity);
    cout << "\nPlease Enter the Employee's Province: ";
    gets(rec.empprovince);
    cout << "\nPlease Enter the Employee's Country: ";
    gets(rec.empcountry);
    cout<<"\nPlease Enter the Employee's Status: ";
    gets(rec.empstatus);
    cout << "\nPlease Enter the Employee's Weekly Gross Salary: ";
    cin >> rec.empsalarygross;

    cout<<"Would you like to return to the main menu?(y), else the program will exit: ";
    cin>>userinputadd;
    if (userinputadd =='y' || userinputadd =='Y')
        main();
    else
        exit();
}

void payroll::modrec(void)          //Record Modification
{
    system("CLS");
    int empmodnum=0;
    check = false;
    char userinputmod = ' ';

    cout<<"\nEnter the employee number for the record you would like to modify: ";
    cin>>empmodnum;

    cout<<"Would you like to return to the main menu?(y), else the program will exit: ";
    cin>>userinputmod;
    if (userinputmod =='y' || userinputmod =='Y')
        main();
    else
        exit();
}

void payroll::viewrec(void)         //Record viewing
{
    system("CLS");
    check = false;
    char userinputview = ' ';

    cout<<"Would you like to return to the main menu?(y), else the program will exit: ";
    cin>>userinputview;
    if (userinputview =='y' || userinputview =='Y')
        main();
    else
        exit();

}

void payroll::exit(void)
{
    inFile1.close();
    inFile2.close();
    check = true;
}

So on the front menu if you hit 1 to add a record you will see it skips the first cin statement being employee number.

Does anyone have an idea why this would occur?

  • 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-01T16:47:10+00:00Added an answer on June 1, 2026 at 4:47 pm

    You probably have a buffer issue so you need to flush stdin. Check google for details.

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

Sidebar

Related Questions

Hey Guys, having an issue with Linq-to-SQL, I am basically doing the following but
Hey guys, working on an event calendar. I'm having some trouble getting my column
Hey guys. I'm having this silly issue with inserting text with forwardslash into cart
Hey guys, I'm having an interesting issue, where I want to have a customized
Hey guys I'm having such a hard time of it today. I have a
Hey guys i want to execute my SQL statement but im having synatx trouble,
Hey guys, I'm having a problem with IE7, my menu always drops down behind
Hey Guys, here is my code for this, the only help i get from
Hey guys I was wondering if anyone could help me with an issue im
Hey guys, I'm brand new to Visual C++, but not C++. I'm having issues

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.