首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LNK 1120和LNK 2001错误

LNK 1120和LNK 2001错误
EN

Stack Overflow用户
提问于 2011-05-12 19:53:39
回答 3查看 584关注 0票数 0

嘿,伙计们,我正在做一个程序,做很多简单的事情,让我的老师知道我已经学会了使用函数。我已经反复阅读了这个论坛,并检查了许多其他论坛,但似乎没有一个能解决我的问题。由于下面的代码是链接的(我认为),我在错误列表中得到以下消息:

错误LNK1120: 1未解决的外部因素

错误LNK2001:未解析的外部符号_mainCRTStartup

有人能帮我解决这个问题吗?

这是我的密码

代码语言:javascript
复制
#include <iostream.h>
#include <math.h>

using namespace std;

int a;
int b;
float c;
int d;

float p_theorem (int side_a, int side_b){
    return sqrtf((side_a * side_a)+(side_b * side_b));
}

float p_theorem_reverse (int side_c, int side_d){
    return sqrtf((side_c * side_c)-(side_d * side_d));
}

void game(int x){
    if (x < 5){
        cout<<"Your number is too low"<<endl<<"Please guess again: ";
        cin>>x;
    }
    else if (x > 5){
        cout<<"Your number is too big"<<endl<<"Please guess again: ";
        cin>>x
    }
    else (x == 5){
        cout<<"Good job, You guessed the number!"<<endl;
        system("PAUSE");
    }
}

void stuff(){
    cout<<"Developed by Ely Eastman"<<endl<<"Computer 35, T.H. Rogers Secondary     School, Houston, TX"<<endl;
    system("PAUSE");
}

int main(void)
{
    cout<<"Welcome to the Multi-Function Program"<<endl
        <<"Enter 1 for finding the hypotenuse of a right triangle"<<endl
        <<"Enter 2 for finding the leg of a right triangle"<<endl
        <<"Enter 3 for the Guessing Game Beta"<<endl
        <<"Enter 4 for Developer Information"<<endl;

    cin>>d
    if (d == 1){
        cout<<"Welcome to the Pythagorean Theorem Solver"<<endl
            <<"Please enter the length of one leg of the     triangle: ";
        cin>>a;
        cout<<"Please enter the length of the other leg of the triangle: ";
        cin>>b;
        c = p_theorem(a, b);
        cout<<"The length of the hypotenuse is "<<c<<endl;
        system("PAUSE");
    }
    else if (d == 2){
        cout<<"Welcome to the Reverse Pythagorean Theorem"<<endl
            <<"Please enter the length of the Hypotenuse: ";
        cin>>a;
        cout<<"Please enter the length of the known leg: ";
        cin>>b;
        c = p_theorem_reverse(a, b);
        cout<<"The length of the leg is: "<<g<<endl;
        system("PAUSE")
    }
    else if (d == 3){
        cout<<"Welcome to the Guessing Game Beta"<<endl
            <<"Please guess a number 1-10: ";
        cin<<a
            game(a);
    }
    else if (d == 4){
        stuff();
    }

    return 0;
}
EN

回答 3

Stack Overflow用户

发布于 2011-05-12 20:02:43

你少了几十个";“和一个失踪的if语句。游戏"g“的长度也是未知的。你的cin ">>“操作符在某些情况下是相反的.

编辑:正如Neil在评论中指出的那样,您可能需要指定正在创建控制台应用程序。

工作吗?代码(请注意我更改了什么,而不仅仅是复制/粘贴它,有些错误是非常基本的知识):

代码语言:javascript
复制
#include <iostream>
#include <math.h>

using namespace std;

int a;
int b;
float c;
int d;

float p_theorem (int side_a, int side_b){
    return sqrtf((side_a * side_a)+(side_b * side_b));
}

float p_theorem_reverse (int side_c, int side_d){
    return sqrtf((side_c * side_c)-(side_d * side_d));
}

void game(int x)
{
    if (x < 5)
    {
        cout<<"Your number is too low"<<endl<<"Please guess again: ";
        cin>>x;
    }
    else if (x > 5){
        cout<<"Your number is too big"<<endl<<"Please guess again: ";
        cin>>x;
    }
    else if (x == 5)
    {
        cout<<"Good job, You guessed the number!"<<endl;
        system("PAUSE");
    }
}

void stuff(){
    cout<<"Developed by Ely Eastman"<<endl<<"Computer 35, T.H. Rogers Secondary     School, Houston, TX"<<endl;
    system("PAUSE");
}

int main(void)
{
    cout<<"Welcome to the Multi-Function Program"<<endl
        <<"Enter 1 for finding the hypotenuse of a right triangle"<<endl
        <<"Enter 2 for finding the leg of a right triangle"<<endl
        <<"Enter 3 for the Guessing Game Beta"<<endl
        <<"Enter 4 for Developer Information"<<endl;

    cin>>d;
    if (d == 1){
        cout<<"Welcome to the Pythagorean Theorem Solver"<<endl
            <<"Please enter the length of one leg of the     triangle: ";
        cin>>a;
        cout<<"Please enter the length of the other leg of the triangle: ";
        cin>>b;
        c = p_theorem(a, b);
        cout<<"The length of the hypotenuse is "<<c<<endl;
        system("PAUSE");
    }
    else if (d == 2){
        cout<<"Welcome to the Reverse Pythagorean Theorem"<<endl
            <<"Please enter the length of the Hypotenuse: ";
        cin>>a;
        cout<<"Please enter the length of the known leg: ";
        cin>>b;
        c = p_theorem_reverse(a, b);
        cout<<"The length of the leg is: "<<c<<endl; // <- What is g?!!! I think you had a typo
        system("PAUSE");
    }
    else if (d == 3){
        cout<<"Welcome to the Guessing Game Beta"<<endl
            <<"Please guess a number 1-10: ";
        cin>>a;
            game(a);
    }
    else if (d == 4){
        stuff();
    }

    return 0;
}
票数 1
EN

Stack Overflow用户

发布于 2011-05-12 20:07:29

假设您在Visual 2005上,请转到项目的 Properties ,打开Configuration Properties Subsystem中的Linker将是列表中的第一项。然后选择Windows (/SUBSYSTEM:WINDOWS)

票数 0
EN

Stack Overflow用户

发布于 2011-05-12 20:40:06

检查项目设置并查看是否设置了/NODEFAULTLIB链接器选项。如果是的话,就取消它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5983678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档