繁体   English   中英

“+1 超载 --- Function 未找到“...”的定义”以及“无法启动程序。系统找不到指定的文件”

[英]"+1 Overload --- Function definition for '...' not found" Along With "Unable to start program. The system cannot find the file specified"

这段代码是为作业而写的,我在作业中提示用户输入以根据患者是住院还是门诊以及用户输入的费率和费用来计算医院账单。 我遇到的问题是,当我尝试运行代码时,系统首先告诉我存在构建错误并询问我是否要继续。 继续后,我收到以下错误消息:

“无法启动程序。[文件路径]系统找不到指定的文件”

我正在检查我的代码,我唯一能看到的是主要 function 之前的 function 原型有一条消息,指出找不到 function 定义。

我的代码有问题还是这纯粹是 Visual Studio 2017 的问题? 我的目录看起来没有乱序之类的。

// PGM6 - Overloaded Hospital - 11.15.2020

#include "pch.h"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

double inpatient(int days, double rateDaily, double chargesService, double chargesMeds, double chargesTotal);
double outpatient(double chargesService, double chargesMeds, double chargesTotal);

int main()
{
    int patientType;

    cout << "Please enter (1) for Inpatient or (2) for Outpatient" << endl;
    cin >> patientType;

    if (patientType == 1)
        double inpatient();
    else 
        if (patientType == 2)
            double outpatient();
        else
            cout << "Please enter (1) or (2)." << endl;
}

double inpatient()
{
    int days;
    double rate;
    double chargesService;
    double chargesMeds;
    double chargesTotal = (days * rate) + chargesService + chargesMeds;

    cout << "Days: ";
    cin >> days;
    cout << endl;

    cout << "Daily Rate: ";
    cin >> rate;
    cout << endl;

    cout << "Service Charges: ";
    cin >> chargesService;
    cout << endl;

    cout << "Medication Charges: ";
    cin >> chargesMeds;
    cout << endl << endl;

    cout << "Total Charges: " << chargesTotal << endl;

    return chargesTotal;

}

double outpatient()
{
    double chargesService;
    double chargesMeds;
    double chargesTotal = chargesService + chargesMeds;

    cout << "Service Charges: ";
    cin >> chargesService;
    cout << endl;

    cout << "Medication Charges: ";
    cin >> chargesMeds;
    cout << endl << endl;

    cout << "Total Charges: " << chargesTotal << endl;

    return chargesTotal;
}

这是你做错了什么

  1. 您的函数原型不需要参数,因为值是由用户在 function 中键入的。
  2. 打电话给门诊和住院的时候,只要把function的名字加上括号就可以了(不要在前面打double,那是新申报的)。
  3. chargesTotal 必须在打印之前初始化(在向用户询问所需的值之后)

我认为这段工作代码可以满足您的需求:


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

using namespace std;

double inpatient();
double outpatient();

int main()
{
    int patientType;

    cout << "Please enter (1) for Inpatient or (2) for Outpatient" << endl;
    cin >> patientType;

    if(patientType == 1)
    inpatient();
    else if(patientType == 2)
    outpatient();
    else
    cout << "Please enter (1) or (2)." << endl;
}

double inpatient()
{
    int days;
    double rate;
    double chargesService;
    double chargesMeds;

    cout << "Days: ";
    cin >> days;
    cout << endl;

    cout << "Daily Rate: ";
    cin >> rate;
    cout << endl;

    cout << "Service Charges: ";
    cin >> chargesService;
    cout << endl;

    cout << "Medication Charges: ";
    cin >> chargesMeds;
    cout << endl << endl;

    double chargesTotal = (days * rate) + chargesService + chargesMeds;

    cout << "Total Charges: " << chargesTotal << endl;

    return chargesTotal;
}

double outpatient()
{
    double chargesService;
    double chargesMeds;

    cout << "Service Charges: ";
    cin >> chargesService;
    cout << endl;

    cout << "Medication Charges: ";
    cin >> chargesMeds;
    cout << endl << endl;

    double chargesTotal = chargesService + chargesMeds;
    cout << "Total Charges: " << chargesTotal << endl;

    return chargesTotal;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM