为什么Visual Studio 2019不编译我的代码?

鲍比

我一直在尝试使此代码正常工作。我主要是自己和Google编写此代码的。我是一个非常初学者,所以我不知道如何解决这个问题。

我试过切割代码,将其转换为c#,(当然要对其进行修改)新文件和其他编译器。

#include <iostream>
using namespace std;

//suurin_luku.cpp 

int question() {
    double answers;
    cout << "Do you want the biggest number, or smallest number?\n";
    cout << "0 for biggers, 1 for smaller.\n";
    cin >> answers;

    if (answers == 0) {
        int biggest();
    }
    if (answers == 1) {
        int smallest();

    }
    return 0;
}






int biggest()
{
    float input1, input2, input3;
    cout << "Please insert three numbers.\n";
    cin >> input1 >> input2 >> input3;
    if (input1 >= input2 && input1 >= input3)
    {
        cout << "The largest number is: " << input1;
    }
    if (input2 >= input1 && input2 >= input3)
    {
        cout << "The largest number is: " << input2;
    }
    if (input3 >= input1 && input3 >= input2) {
        cout << "The largest number is: " << input3;
    }
    return 0;
}

int smallest()
{
    float input11, input22, input33;
    cout << "Insert three numbers.";
    cin >> input11 >> input22 >> input33;
    if (input11 <= input22 && input11 <= input33)
    {
        cout << "The smallest number is: " << input11;
    }
    if (input22 <= input11 && input22 <= input33)
    {
        cout << "The smallest number is: " << input22;
    }
    if (input33 <= input11 && input33 <= input22) {
        cout << "The smallest number is: " << input33;
    }
    return 0;
    }

用户输入0时,显示最大输入数字。用户输入1时,显示输入的最小数字。错误代码为LNK1120和LNK2019。

火焰

如果这就是您的所有代码,则可能会因为缺少main函数而收到链接错误如果我main在VS项目中省略则会得到两个确切的链接错误将此添加到您的代码:

int main() {
    question();
}

另外,您没有在调用函数,只是在声明它们:

if (answers == 0) {
    int biggest();
}
if (answers == 1) {
    int smallest();
}

删除那些int以调用函数。您必须int question()将这两个其他函数放在下面,否则将无法找到它们,除非事先声明它们,如下所示:

int biggest(); // declaring them so question() knows their signature
int smallest();
int question() { ... }; // question() calls biggest() and smallest()
int biggest() { ... }; // actual implementation of those functions
int smallest() { ... };
int main { ... }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么允许此代码在Visual Studio 2013下编译?

为什么Visual Studio不了解“线程”?

为什么Visual Studio代码无法运行我的代码?

为什么我在Visual Studio和Qt上编译相同的代码,却得到不同的结果?

为什么我的代码无法在Visual Studio Code中运行?

为什么Visual Studio忽略我编写的新代码?

转移到 Visual Studio 2019 后,我的生产代码停止编译

在执行Visual Installer更新后,为什么我的Visual Studio 2019 Pro调试速度如此慢?

为什么XmlSerializer在Visual Studio 2019中不会导致FileNotFoundException?

Visual Studio 2019 C ++对概念的支持-成功编译并出现错误:为什么?

为什么此代码会使Visual Studio 2015崩溃?

为什么Visual Studio 2012找不到我的测试?

为什么我的Visual Studio Code任务没有执行?

为什么Visual Studio会尝试注册我的DLL

为什么我的 Visual Studio 项目模板的描述不显示?

为什么在Visual Studio中我= i ++使其增加

为什么Visual Studio无法提取我的类库?

为什么Visual Studio会删除我的文件

为什么 Visual Studio 以不同的方式对待我的对象?

为什么我的某些 Visual Studio Code 扩展被禁用

为什么我无法在 Linux 上打开 Visual Studio Code?

为什么 Visual Studio 2019 会自动设置 git 源代码控制?

为什么此C代码在Codeblock中而不在Visual Studio中进行编译?

为什么在常规IDE(如Visual Studio代码)上编译时,“ this”会返回Empty对象?

更改代码 Visual Studio 2019 后编译错误

为什么Visual Studio 2019将无法运行我的单元测试?

为什么我的SSIS工具箱在Visual Studio 2019社区中为空?

为什么我在 Microsoft Visual Studio 2019 中看不到设计器视图?

为什么Visual Studio 2019在我的项目中添加<TypeScriptCompile Remove />?