C++ 工资单数组打印输出

C++ 工资单数组打印输出,c++,C++,我已经尽了最大努力来清除这个程序中的错误,但仍然一无所获。我已经搜索过了,但还没有找到解决办法 编写一个使用以下数组的程序: •empId:一个包含七个长整数的数组,用于保存员工标识号。应使用以下数字初始化阵列: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 •小时数:由七个整数组成的数组,用于保存每位员工的工作小时数 •工资率:七倍的数组,用于保持每位员工的小时工资率 •工资:七倍的数组,用于保存每位员工的总工资 程序应该通过下

我已经尽了最大努力来清除这个程序中的错误,但仍然一无所获。我已经搜索过了,但还没有找到解决办法

编写一个使用以下数组的程序:

•empId:一个包含七个长整数的数组,用于保存员工标识号。应使用以下数字初始化阵列:

5658845 4520125 7895122 8777541 8451277 1302850 7580489

•小时数:由七个整数组成的数组,用于保存每位员工的工作小时数

•工资率:七倍的数组,用于保持每位员工的小时工资率

•工资:七倍的数组,用于保存每位员工的总工资

程序应该通过下标关联每个数组中的数据。例如,小时数数组元素0中的数字应该是员工的工作小时数,其识别号存储在empId数组元素0中。该员工的工资率应存储在工资率数组的元素0中

该程序应显示每个员工编号,并要求用户输入该员工的工时和工资率。然后,它应该计算该员工的总工资(小时乘以工资率),并将其存储在工资数组中

输入所有员工的数据后,程序应显示每个员工的身份证号码和工资总额

输入验证:不接受小时数的负值或工资率小于15.00的数字

我的代码如下:

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


int main()
{
    //constant 
    const int empId = 7;
    //arrays initialized with manual entries
    int workers[empId] = { 5658845, 4520125, 7895122,
        8777541, 8451277, 1302850,
        7580489 };
    int hours[empId];
    double payRate[empId];

    //outputs for user entries
    cout << "Please enter the hours worked by " << empId
        << " employees and their\n"
        << "hourly pay rates.\n";
    //loops for each employee
    for (int index = 0; index < empId; index++)
    {
        cout << "Please enter the hours worked by employee number " << (index + 1) << " (ID = " << workers[index] << ") : ";
        cin >> hours[index];
        cout << "Please enter the pay rate for employee number " << (index + 1) << " (ID = " << workers[index] << ") : ";
        cin >> payRate[index];
    }
    do
    {
        cout << "Please enter the hours worked by employee number " << (index + 1) << " (ID = " << workers[index] << ") : ";
        cin >> hours[index];
    }
    if (hours[index] < 0); //data validation
    {
        cout << "Enter in a positive number" << endl;
    }
    while
    {
        (hours[index] < 0)

    do

        cout << "Please enter the pay rate for employee number " << (index + 1) << " (ID = " << workers[index] << ") : ";
        cin >> payRate[index];
    }
    if (payRate[index] < 15)  //data validation for pay rate
    {
        cout << "The pay rate must be >= 15" << endl;
    }
    //outputs for reults
    while (hours[index] < 6);
    {
        cout << "This is the gross pay for each employee:\n";
        cout << fixed << showpoint << setprecision(2);
    }
    for (int index = 0; index < empId; index++)
    {
        double grossPay = hours[index] * payRate[index];
        cout << "Employee #" << (index + 1);
        cout << ": earned $" << grossPay << endl << endl;
    }
    return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
//不变的
const int empId=7;
//使用手动条目初始化数组
国际工人[empId]={56588454201257895122,
8777541, 8451277, 1302850,
7580489 };
整小时[empId];
双倍工资率[empId];
//用户输入的输出

cout您的
do
循环中存在语法错误

并且您没有遵守助理的要求:

  • 您的
    workers
    数组需要命名为
    empId

  • 您缺少一个
    数组

  • 您没有正确验证用户的输入

请尝试类似以下内容:

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

int main()
{
    //constant 
    const int numEmployees = 7;

    //arrays initialized with manual entries
    int empId[numEmployees] = { 5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489 };
    int hours[numEmployees];
    double payRate[numEmployees];
    double wages[numEmployees];

    //inputs for user entries
    cout << "Please enter the hours worked by " << numEmployees << " employees\n"
         << "and their hourly pay rates.\n";

    //loops for each employee
    for (int index = 0; index < numEmployees; index++)
    {
        do
        {
            cout << "Please enter the hours worked by Employee # " << (index + 1) << " (ID = " << empId[index] << ") : ";
            if (cin >> hours[index])
            {
                if (hours[index] > 0) //data validation
                    break;

                cout << "Enter in a positive number" << endl;
            }
            else
            {
                cin.ignore(numeric_limits<streamsize>::max(), '\n');
                cin.clear();
                cout << "Enter in a valid number" << endl;
            }
        }
        while (true);

        do
        {
            cout << "Please enter the pay rate for Employee # " << (index + 1) << " (ID = " << empId[index] << ") : ";
            if (cin >> payRate[index])
            {
                if (payRate[index] >= 15.0)
                    break;

                cout << "The pay rate must be >= 15" << endl;
            }
            else
            {
                cin.ignore(numeric_limits<streamsize>::max(), '\n');
                cin.clear();
                cout << "Enter in a valid monetary value" << endl;
            }
        }
        while (true);

        wages[index] = hours[index] * payRate[index];
    }

    //outputs for results

    cout << "This is the gross pay for each employee:\n";
    cout << fixed << showpoint << setprecision(2);

    for (int index = 0; index < numEmployees; index++)
    {
        cout << "Employee #" << (index + 1) << " (ID = " << empId[index] << ") : ";
        cout << "earned $" << wages[index] << endl << endl;
    }

    return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
//不变的
雇佣人数=7人;
//使用手动条目初始化数组
int empId[Numemememployees]={5658845445201257895122877754184512713028507580489};
整小时[雇用人数];
双倍工资率[雇员人数];
双倍工资[雇员];
//用户条目的输入

有什么错误吗?你有一个
do
漂浮在空中,我打赌这就是其中之一(评论编辑:我猜你的错误是编译错误)作为漂浮在空中的
do
的装置,你在
for
之外使用变量
索引
,而
for
的初始声明中声明了这一点一个重要提示:不要为了修复bug而写一堆代码。相反,这有点极端,但绝对没有那么大的压力:编写一个line、 编译,修正错误,写下一行非常感谢,我还在学习,学校里几乎没有辅导中心,但我会用它来学习。