首页 > 解决方案 > 'g++' 不是内部或外部命令、可运行程序或批处理文件。视觉工作室代码

问题描述

我正在编写一个从输入文件“payroll.txt”读取数据的程序。我已经使用记事本创建了文件。但是我遇到了一个问题当我运行程序时,我收到以下错误:'g++' 不被识别为内部或外部命令、可运行程序或批处理文件。 我已经安装了 minGW- 并在系统环境变量设置中配置了 PATH。在此处输入图像描述 这是我的代码

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

void instructions();

void reportTitle();

void displayEmployeeInfo(string employeeName, double hourlyRate,
    double hoursWorked, double taxRate, double grossAmount,
    double netAmount);

void totalAmounts(double totalGrossAmount, double totalNetAmount);

int main()
{
    ifstream infile;
    string employeeName;
    double hourlyRate, hoursWorked, taxRate, grossAmount, netAmount,
        totalGrossAmount = 0.0, totalNetAmount = 0.0;

    infile.open("payroll.txt");

    if (!infile) {
        cout << "Input failed." << endl;
        return 1;
    }

    instructions();
    reportTitle();

    getline(infile, employeeName, '#');
    infile >> hourlyRate >> hoursWorked >> taxRate;
    infile.ignore(100, '\n');

    while (!infile.eof()) {
        grossAmount = hoursWorked * hourlyRate;

        if (hoursWorked > 40)
            grossAmount += (hoursWorked * hourlyRate * .5);

        netAmount = grossAmount - (grossAmount * taxRate / 100);

        totalGrossAmount += grossAmount;

        totalNetAmount += netAmount;

        displayEmployeeInfo(employeeName, hourlyRate, hoursWorked, taxRate,
            grossAmount, netAmount);

        getline(infile, employeeName, '#');
        infile >> hourlyRate >> hoursWorked >> taxRate;
        infile.ignore(100, '\n');
    }

    totalAmounts(totalGrossAmount, totalNetAmount);
    return 0;
}

void instructions()
{
    cout << "This payroll program calculates an individual "
         << "employee pay and\ncompany totals "
         << "using data from a data file payroll.txt. \n"
         << "\n\nA payroll report showing payroll information "
         << "is displayed.\n\n";
}

void reportTitle()
{
    cout << setprecision(2) << fixed << showpoint << left;
    cout << setw(24) << "Employee" << setw(11) << "Hourly"
         << setw(11) << "Hours" << setw(9) << "Tax"
         << setw(11) << "Gross" << setw(10) << "Net" << endl;
    cout << setw(25) << "Name" << setw(9) << "Rate" << setw(12)
         << "Worked" << setw(8) << "Rate" << setw(10) << "Amount"
         << setw(10) << "Amount" << endl
         << endl;
}

void displayEmployeeInfo(string employeeName, double hourlyRate,
    double hoursWorked, double taxRate, double grossAmount,
    double netAmount)

{
    cout << left << setw(25) << employeeName << right << setw(5)
         << hourlyRate << setw(10) << hoursWorked << setw(10) << taxRate
         << setw(10) << grossAmount << setw(10) << netAmount << endl;
}

void totalAmounts(double totalGrossAmount, double totalNetAmount)
{

    cout << left << setw(26) << "\nTotals" << right << setw(35)
         << totalGrossAmount << setw(10) << totalNetAmount << endl;
}

标签: c++visual-studio-codeg++

解决方案


推荐阅读