2011-05-12 81 views
0

嘿,我正在開發一個程序,它執行許多簡單的事情來向我的老師表明我已經學會了使用函數。我已經多次閱讀這個論壇,並檢查了許多其他的,但他們都沒有解決我的問題。 如下面的代碼是連接(我認爲),我得到的錯誤列表這些消息:錯誤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<<"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; 
} 
+2

這個程序如何進入連接階段? 'else(x == 5){}'。 「超鏈接」標籤與你的程序有什麼關係? – Mahesh 2011-05-12 19:59:48

+1

你有幾十個失蹤的「;」以及缺少陳述。此外,遊戲「g」的長度未定義。在某些情況下,你的cin「>>」操作符被顛倒過來...... – Pepe 2011-05-12 20:01:03

+2

爲了避免歇斯底里,我懷疑你創建了一個Windows GUI項目,當你真的想創建一個Windows控制檯項目時。 – 2011-05-12 20:05:50

回答

1

你有幾十個失蹤的 「;」以及缺少陳述。此外,遊戲「g」的長度未定義。並且在某些情況下,您的cin「>>」操作符會顛倒過來...

編輯:正如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<<"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; 
} 
0

假設你是在Visual Studio 2005中,去的的屬性項目,打開鏈接器配置屬性 子系統將是名單上的第一項。然後選擇Windows (/SUBSYSTEM:WINDOWS)

+0

將'/ SUBSYSTEM'設置爲'WINDOWS'將使鏈接器查找'WinMain'或'wWinMain'。他顯然希望'/ SUBSYSTEM:CONSOLE',因此鏈接器將查找'main'或'wmain'。 – ildjarn 2011-05-12 20:32:50

+0

好的,謝謝。但讓我們先聽聽他的輸入。 – karlphillip 2011-05-12 20:36:23

0

檢查您的項目設置並查看是否設置了/NODEFAULTLIB鏈接器選項。如果是,請取消設置。