0

我正在开发一个计算员工每月销售数据并将每个数据与年度配额数据进行比较的程序。它比较了每位员工十二次,它会显示哪个员工做得最差,有多少员工错过了至少一个月度数据,以及基于最后一次计算的百分比。这是我的代码

#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <iomanip>
using namespace std;

int main()
{

    int numEmployee = 0;
    string employeeName;
    int yearQuota = 0;
    int monthQuota = 0;
    int quotaMissed = 0;
    int quotaMet = 0;
    int maxMissed = 0;
    string maxEmployee;
    int missedAmount = 0; //Amount of employee's that missed at least one quota
    bool missedOne = false;
    double quotaPercent = 0;
    ifstream reader ("data.txt");

    cout << "Employee Name" << "     Yearly Quota" << "                       Monthly                 Sales" << "\n\n";

    reader >> numEmployee;
    for (int i = numEmployee; i > 0; i--)
    {
        reader >> employeeName;
        cout << "   " << employeeName;
        reader >> yearQuota;
        cout << "            " << yearQuota;
        cout << "               ";
        for (int b = 12; b > 0; b--)
        {
            reader >> monthQuota;
            if (monthQuota < yearQuota)
            {
                quotaMissed += 1;
                missedOne = true;
            }
            else
            {
                quotaMet += 1;
            }
            cout << monthQuota << " ";
            reader.clear();
        }
        if (missedOne)
        {
            missedAmount += 1;
        }
        cout << quotaMissed << " ";
        cout << quotaMet << " ";

        if (quotaMissed > maxMissed)
        {
            maxMissed = quotaMissed;
            maxEmployee = employeeName;
        }
        cout << "\n\n";
    }
    cout << "\n\n";
    quotaPercent = static_cast<double>(missedAmount) / numEmployee;
    quotaPercent *= 100;
    if (quotaPercent > 20)
    {
        cout << "A Sell It! Or Else Campaign Needs To Be Initiated!";
        cout << quotaPercent << "%" << " of the employee's didn't meet their quota's";
        cout << "Consider Firing: " << maxEmployee;
    }
    else
    {
        cout << "A Sell It! Or Else Campaign Doesn't Need To Be Initiated!";
        cout << "only " << quotaPercent << "%" << " of the employee's didn't meet their quota's";
    }
    _getch();

    return 0;
}

一切对我来说似乎都很简单,但是当我运行我的程序时,会发生一些非常奇怪的事情。它在低于年度配额的每个月销售数据列表的末尾添加两个数字。这些数字不在数据文件中,并且添加了循环不应该计算的额外两个数字。但是,当程序运行时,它会计算这些数字,因此,无论数据文件中包含什么信息,“100% 的员工”总是缺少配额。有效地使该软件无用。我一直在查看代码一段时间,并没有提出任何解决方案。如果有人可以帮助我,我将不胜感激。

4

0 回答 0