【发布时间】:2018-03-30 23:22:20
【问题描述】:
本周我的计算机科学入门课程刚刚介绍了函数,在检查了“未解析的外部符号”的主要线程之后,我认为它要么是
a) 你声明了函数,但从未在 main 之后调用它们
b) 您缺少正确的库
我只是不确定它是哪一个或如何正确地去做。另外,我认为我的逻辑在 calcSideC 块中略有缺陷,尽管我不确定
#include <iostream>
#include <cmath>
using namespace std;
float getSide();
float calcSideC(float sideA, float sideB, float total);
void displaySideC(float sideC);
int main()
{
{
float sideA = 0.0;
float sideB = 0.0;
float total = sideA + sideB;
float sideC = sqrt(total);
sideA = getSide();
sideB = getSide();
sideC = calcSideC(sideA, sideB, total);
displaySideC(sideC);
return 0;
}
float getSide();
{
float sideA;
cout << "Enter two sides of a right triangle.\n\n" << "Side A: \n" << "Please enter the dimension: ";
cin >> sideA;
return sideA;
}
float getSide();
{
float sideB;
cout << "\n\n" << "Side B: \n" << "Please enter the dimension: ";
cin >> sideB;
return sideB;
}
float calcSideC(float sideA, float sideB, float total);
{
float sideA;
float sideB;
float total;
float sideC;
pow(sideA, 2);
pow(sideB, 2);
float sqrt(total);
return sideC;
}
void displaySideC(float sideC);
{
float sideC;
cout << "The dimension of Side C is: " << sideC;
}
system("pause");
return 0;
}
【问题讨论】:
-
你从来没有定义你的函数,比如
getSide和其他。因此链接器错误。