错误LNK 1120和LNK 2001 [英] error LNK 1120 and LNK 2001

查看:200
本文介绍了错误LNK 1120和LNK 2001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在做一个程序,做了很多简单的事情,显示我的老师,我已经学会使用功能。我已经反复阅读这个论坛,并检查了许多其他的,但没有一个似乎解决我的问题。
下面的代码是链接(我想),我得到这些错误列表中的消息:


错误LNK1120:1未解决的外部

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




<

这是我的代码

  #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<<请再猜一次:;
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<<由Ely Eastman开发<<< endl< Rogers Secondary School,Houston,TX<<< endl;
system(PAUSE);
}

int main(void)
{
cout<<Welcome to the Multi-Function Program<< endl
< ;<输入1以找到直角三角形的斜边<<<输入2用于发现直角三角形的边<< endl
< ;<为猜测游戏Beta输入3<< endl
<<为开发者信息输入4<< endl;

cin>> d
if(d == 1){
cout<<Welcome to the Pythagorean Theorem Solver<< endl
<<请输入三角形的一条腿的长度:;
cin>> a;
cout<<请输入三角形另一条腿的长度:;
cin>> b;
c = p_theorem(a,b);
cout<<斜边的长度为<< c<< endl;
system(PAUSE);
}
else if(d == 2){
cout<<欢迎来到逆向毕达哥拉斯定理<< endl
< Hypotenuse的长度:;
cin>> a;
cout<<请输入已知腿长度:;
cin>> b;
c = p_theorem_reverse(a,b);
cout<<腿的长度是:<< g<< endl;
system(PAUSE)
}
else if(d == 3){
cout<<Welcome to the Guessing Game Beta<< endl
<<请猜数字1-10:;
cin<< a
game(a);
}
else if(d == 4){
stuff();
}

return 0;
}


解决方案

;和一个缺少的if语句。此外,游戏g的长度未定义。你的cin>>操作符在某些情况下是相反的...



编辑:As Neil在评论中指出,你可能需要指定你创建控制台应用程序。



工作?代码(请尝试注意我改变了什么,而不是复制/粘贴它,一些错误是相当基本的知识):

  #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<数字太低<<< endl<<请再猜:
cin>> x;
}
else if(x> 5){
cout<<<Your number is too big<< endl<<Please guess again:
cin>> x;
}
else if(x == 5)
{
cout<<好工作,你猜到了数字!<< endl;
system(PAUSE);
}
}

void stuff(){
cout<<由Ely Eastman开发<<< endl< Rogers Secondary School,Houston,TX<<< endl;
system(PAUSE);
}

int main(void)
{
cout<<Welcome to the Multi-Function Program<< endl
< ;<输入1以找到直角三角形的斜边<<<输入2用于发现直角三角形的边<< endl
< ;<为猜测游戏测试版输入3<< endl
<<为开发者信息输入4<< endl;

cin>> d;
if(d == 1){
cout<<欢迎来到毕达哥拉斯定理解算器< <三角形:;
cin>> a;
cout<<请输入三角形另一条腿的长度:;
cin>> b;
c = p_theorem(a,b);
cout<<斜边的长度为<< c<< endl;
system(PAUSE);
}
else if(d == 2){
cout<<欢迎来到逆向毕达哥拉斯定理<< endl
< Hypotenuse的长度:;
cin>> a;
cout<<请输入已知腿长度:;
cin>> b;
c = p_theorem_reverse(a,b);
cout<<腿的长度是:<< c<< endl; //< - 什么是g?我想你有一个typo
系统(PAUSE);
}
else if(d == 3){
cout<<欢迎来到猜测游戏测试版< <数字1-10:;
cin>> a;
game(a);
}
else if(d == 4){
stuff();
}

return 0;
}


Hey guys i am working on a program that does many simple things to show my teacher that i have learned to use functions. i have repeatedly read this forum and checked many other ones but none of them seem to solve my problem. as the code below is linking ( i think ), I get these messages in the error list:

error LNK1120: 1 unresolved externals
error LNK2001: unresolved external symbol _mainCRTStartup

Can someone please help me solve this!

Here is my code

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

解决方案

You have dozens of missing ";" and a missing if statement. Also the length of the game "g" is undefined. And your cin ">>" operators are reversed in some cases ...

Edit: As Neil pointed out in the comments, you probably need to specify that you are creating a console application.

Working? Code (Please try to notice what I changed and not just copy/paste it, some of the mistakes are pretty basic knowledge):

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

这篇关于错误LNK 1120和LNK 2001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆