简体   繁体   English

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

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

This code is written for homework where I am prompting user input to calculate hospital bills based on whether the patient was admitted as an inpatient or an outpatient, along with user-inputted rates and charges.这段代码是为作业而写的,我在作业中提示用户输入以根据患者是住院还是门诊以及用户输入的费率和费用来计算医院账单。 The issue I am having is that when I try to run the code, the system first tells me that there are build errors and asks if I would like to continue.我遇到的问题是,当我尝试运行代码时,系统首先告诉我存在构建错误并询问我是否要继续。 After continuing, I get the following error message:继续后,我收到以下错误消息:

"Unable to start program. [File Path] The system cannot find the specified file" “无法启动程序。[文件路径]系统找不到指定的文件”

I was going through my code and the only thing I could see was that the function prototypes before the main function had a message stating that the function definition could not be found.我正在检查我的代码,我唯一能看到的是主要 function 之前的 function 原型有一条消息,指出找不到 function 定义。

Are there issues with my code or is this purely an issue with Visual Studio 2017?我的代码有问题还是这纯粹是 Visual Studio 2017 的问题? My directory doesn't look out of order or anything like that.我的目录看起来没有乱序之类的。

// 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;
}

Here is what you did wrong这是你做错了什么

  1. The prototypes of your functions didn't need parameters as the values are typed by the user within the function.您的函数原型不需要参数,因为值是由用户在 function 中键入的。
  2. When you call outpatient and inpatient, just type the name of the function with the parenthesis (don't type double in front, that's a new declaration).打电话给门诊和住院的时候,只要把function的名字加上括号就可以了(不要在前面打double,那是新申报的)。
  3. chargesTotal had to be initialized just before printing it (after asking the needed values to the user) chargesTotal 必须在打印之前初始化(在向用户询问所需的值之后)

I think this working code do what you need:我认为这段工作代码可以满足您的需求:


#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.

相关问题 错误:无法启动程序“*.exe”系统找不到指定的文件 - Error: unable to start program "*.exe" the system cannot find the file specified 视觉工作室。 无法启动程序 &#39;&#39; 系统找不到指定的文件 - Visual Studio. Unable to start program '' The system cannot find the file specified Visual Studio:无法启动程序,系统找不到指定的文件 Visual Studio 错误? - Visual Studio: Unable to start program, the system cannot find the file specified visual studio error? 无法启动程序VS2015 | 访问被拒绝| 系统找不到指定的文件 - Unable to start program VS2015 | Access denied | system cannot find the file specified 无法启动“program.exe” 系统找不到vs2008指定的文件 - unable to start "program.exe" the system cannot find the file specified vs2008 无法启动程序:系统找不到指定的文件。 (C ++ BTW) - Unable to Start Program: The system cannot find the file specified. (C++ BTW) C ++错误:“无法启动程序&#39;filepath.exe&#39;,系统找不到指定的文件 - C++ error: "Unable to start program 'filepath.exe' The system cannot find the file specified 构建失败? “无法启动程序……系统找不到指定的文件” - Build Failure? “Unable to start program… The system cannot find the file specificed” Visual Studio 调试器错误:无法启动程序 找不到指定文件 - Visual Studio debugger error: Unable to start program Specified file cannot be found Visual Studio2012。“无法启动程序” * .exe“找不到指定的文件” - Visual Studio 2012. “unable to start program” *.exe “cannot find the file specified”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM