C++ 计算函数c+出现问题+;

C++ 计算函数c+出现问题+;,c++,C++,我的程序是一个简单的工资计算器 如果员工类型为0,则任何超过40小时的工作时间都是一个半小时。 如果类型为1,他们就不会加班,而是直接获得工资 我试图保存结构数组中的所有数据。这是一个家庭作业,我的程序符合要求,但我遇到的问题是,在我为员工输入小时数,然后选择菜单选项c后,我的输出为零 我不知道为什么除了列中的零之外没有任何数据输出。我的编译器中没有错误 我做错了什么 C++ #include <iostream> #include <iomanip> #include

我的程序是一个简单的工资计算器

如果员工类型为0,则任何超过40小时的工作时间都是一个半小时。 如果类型为1,他们就不会加班,而是直接获得工资

我试图保存结构数组中的所有数据。这是一个家庭作业,我的程序符合要求,但我遇到的问题是,在我为员工输入小时数,然后选择菜单选项c后,我的输出为零

我不知道为什么除了列中的零之外没有任何数据输出。我的编译器中没有错误

我做错了什么

C++

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


//*********************************************************************************************
//         Structure to hold employee ID, Name, Pay rate per hour, Employee type
//*********************************************************************************************

struct employeeRecord {
    int IDnum;    // holds employee id number
    string name;    // holds employess name
    float payRate;    // holds employee pay rate
    int empType;    // holds employee type
};

//*********************************************************************************************
//                         structure to hold time sheet
//*********************************************************************************************

struct timeSheet{
    float hours;    //hours worked
    float grossPay;    // gross pay
    float netPay;    // net pay
    float taxAmount;    // tax amount deduction
};

//*********************************************************************************************
//                               function prototype
//*********************************************************************************************
void addEmployee(employeeRecord *employee, int &index);
void addTime(timeSheet *time, employeeRecord *employee, int &index);
void calcTime(timeSheet *time, employeeRecord *employee, int &index, float taxRate);
void outTime(timeSheet *time, employeeRecord *employee, int &index);


//*********************************************************************************************
//                                 main function
//*********************************************************************************************

int main(){


    float taxRate = .15;    // taxrate on pay
    char choice;    // holds user choice option
    int index = 0; // index of array

    // create struct arrays to hold data
    employeeRecord employee[2];
    timeSheet time[2];

    // menu title
    cout << "\nArmadillo Automotive Group Payroll\n" << endl;

//*********************************************************************************************
//               do loop to cycle through menu options & validate input
//*********************************************************************************************
    do{
        //menu
        cout << "\nMenu Options: \n";
        cout << "A - Add Employee" << endl;
        cout << "B - Add Employee's Hours" << endl;
        cout << "C - Print Payroll Report" << endl;

        //take user menu choice
        cout << "\nEnter Menu Option: ";
        cin >> choice;
        choice = tolower(choice);

        //validate user selection
        while (choice != 'a' && choice != 'b' && choice!= 'c'){
            cout << "Please enter 'A' 'B' or 'C' : ";
            cin >> choice;
        }

        // Process menu selection choice
        if (choice != 'c'){
            if (choice == 'a'){
                //process new employee
                if (index < 2){
                    addEmployee(employee, index);
                }

                else{
                    cout << "\nEmployee index full" << endl;
                }
            }
            // if choice 'b' add employee work hours
            else{
                addTime(time, employee, index);
            }


        }   

    }while (choice != 'c');

    // calculates and stores employees time sheet information in struct array
    calcTime(time, employee, index, taxRate);

    //display pay check outputs
    outTime(time, employee, index);

    return 0;
}




//*********************************************************************************************
//                    function to add employee to index
//*********************************************************************************************
void addEmployee(employeeRecord *employee, int &index){
    //take employees ID #
    cout << "\nEnter employee's ID number: ";
    cin >> employee[index].IDnum;

    //validate employee id # is greater than 0
    while (employee[index].IDnum < 0){
        cout << "\nPlease enter an ID # above 0 : ";
        cin >> employee[index].IDnum;
    }

    //take employees name
    cout << "\nEnter employee's Name: ";
    cin.ignore();
    getline(cin, employee[index].name);

    //validate line has characters only
    //**********************
    //**********************
    //**********************

    //take employees payrate
    cout << "\nEnter employee's pay rate: $";
    cin >> employee[index].payRate;

    //validate payrate is amount above 0
    while(employee[index].payRate < 0){
    cout << "\nPlease enter a value greater than 0: ";
    cin >> employee[index].payRate;
    }

    // take employees emptype
    cout << "\nEnter Employee type \n";
    cout << "0 for union, 1 for management: ";
    cin >> employee[index].empType;

    //validate 0 or 1 was entered
    while(employee[index].empType != 0 && employee[index].empType != 1){
    cout << "Enter 1 or 0: ";
    cin >> employee[index].empType;
    }

    // increment index for future entry
    index++;
}

//*********************************************************************************************
//                    function to add time to an employee
//*********************************************************************************************

void addTime(timeSheet *time, employeeRecord *employee, int &index){

    //set index to zero to start with first employee on list
    index = 0;
    //main instruction
    cout << "Enter timecard information for each employee: " << endl;

    //enter hours for each employee for loop
    for(int i=0; i < 2; i++){
    cout << "Hours worked for " << employee[index].name << ": ";
    cin >> time[index].hours;
    index++;}
}

//*********************************************************************************************
//                    function to to calculate timesheet
//*********************************************************************************************

void calcTime(timeSheet *time, employeeRecord *employee, int &index, float taxRate){
    index = 0;    // set index back to zero to start at first array index
    float tempHours;    //temp hour hold
    float overTime;    // overTime hours
    float hours = time[index].hours;    //hours worked 
    float grossPay = time[index].grossPay;    //employes's gross pay
    float netPay = time[index].netPay;    //employes's net pay
    float taxAmount = time[index].taxAmount;    ////employes's tax deduction
    int empType = employee[index].empType;    // employee type
    float payRate = employee[index].payRate;    // employes pay rate

    for (int i=0; i < 2; i++){
        if (empType == 0){
            if(hours > 40){
                tempHours = 40;
                overTime = hours - 40;
                grossPay = (overTime * (payRate * 1.5)) + (tempHours * payRate);
                taxAmount = grossPay * taxRate;
                netPay = grossPay - taxAmount;
            }
            else{
                grossPay = hours * payRate;
                taxAmount = grossPay * taxRate;
                netPay = grossPay - taxAmount;
            }
        }
        else{
            grossPay = hours * payRate;
            taxAmount = grossPay * taxRate;
            netPay = grossPay - taxAmount;
        }

        // increase index number
        index++;

    }
}

//*********************************************************************************************
//                    function to to print out timesheet
//*********************************************************************************************

void outTime(timeSheet *time, employeeRecord *employee, int &index){
    index = 0;    // set index back to zero to start at first array index
    int empID = employee[index].IDnum;    //employes id number
    string name = employee[index].name;    // employees name
    float grossPay = time[index].grossPay;    //employes's gross pay
    float taxAmount = time[index].taxAmount;    ////employes's tax deduction
    float netPay = time[index].netPay;    //employes's net pay

    cout << "Pay Roll Report\n" << endl;
    cout << setw(10) << left << "ID" << setw(30) << left << "Name";
    cout << setw(10) << right << "Gross Pay" << setw(10) << right << "Tax";
    cout << setw(10) << right << "Net Pay" << endl;

    // for loop to display employee information.'
    for (int i=0; i < 2; i++){
    cout << setw(10) << left << empID << setw(30) << left << name;
    cout << setw(10) << right << grossPay << setw(10) << right << taxAmount;
    cout << setw(10) << right << netPay << endl;
    index++;}

}
#包括
#包括
#包括
使用名称空间std;
//*********************************************************************************************
//用于保存员工ID、姓名、每小时工资率、员工类型的结构
//*********************************************************************************************
结构雇员记录{
int IDnum;//保存员工id号
string name;//保存雇员的姓名
浮动工资率;//保留员工工资率
int empType;//保存员工类型
};
//*********************************************************************************************
//保存时间表的结构
//*********************************************************************************************
结构时间表{
浮动小时数;//工作小时数
浮动总工资;//总工资
浮动净支付;//净支付
浮动税额;//税额扣除
};
//*********************************************************************************************
//功能原型
//*********************************************************************************************
无效添加员工(员工记录*员工,整数和索引);
无效添加时间(时间表*时间,员工记录*员工,整数和索引);
作废计算时间(时间表*时间,员工记录*员工,内部和索引,浮动税率);
无效超时(时间表*时间,员工记录*员工,整数和索引);
//*********************************************************************************************
//主要功能
//*********************************************************************************************
int main(){
浮动税率=.15;//工资税率
char choice;//保存用户选择选项
int index=0;//数组的索引
//创建结构数组以保存数据
employeeRecord员工[2];
时间表时间[2];
//菜单标题

不欢迎使用Stack Overflow。请花几分钟时间查看我们的,特别是上的页面。这不仅仅是为了让我们的工作更轻松(这将吸引更多的人尝试帮助您),这本身就是一项至关重要的编码技能。你做错了什么?你在没有测试的情况下编写了太多的代码,而现在出现故障的部分又与许多不相关的代码纠缠在一起。你是否使用编译器的调试器逐步完成了代码?如果没有,为什么没有?你需要认真反思
addTime
函数和w它起作用了。