c++ - 2个小错误,我无法用C++理解!

标签 c++ compiler-errors linear-algebra calculator

我有一些小问题,我无法像大脑那样使我的新菜鸟转!我在做什么错我得到了错误:

C:\Users\George\Desktop\linear_equation_calc\main.cpp||In function 'int main(int, const char**)':|

C:\Users\George\Desktop\linear_equation_calc\main.cpp|101|error: 'calcparallelplugin' was not declared in this scope|

C:\Users\George\Desktop\linear_equation_calc\main.cpp|104|error: 'else' without a previous 'if'| ||=== Build finished: 2 errors, 0 warnings ===|

#include <iostream>
#include <string.h>

using namespace std;

// Function includes
// I try to keep them in the order they appear in the
// output below for organization purposes
#include "calc.m.xy12plugin.cpp"
#include "calc.b.xymplugin.cpp"
#include "calc.m.xybplugin.cpp"
#include "calc.point.xymplugin.cpp"
#include "calc.parallelplugin.cpp"

// The above one would be here, too

int main(int argc, const char* argv[]) {
int i;
i = 0;
cout << "Linear Equation Calculator" << endl << "Copyright (c) 2011 Patrick Devaney" << endl
<< "Licensed under the Apache License Version 2" << endl;
// This loop makes the code a bit messy,
// but it's worth it so the program doesn't
// crash if one enters random crap such as
// "zrgxvd" or "54336564358"
while(i < 1) {
cout << "Type:" << endl
<< "0 to calculate a slope (the M value) based on two points on a line" << endl
<< "1 to calculate the Y-intercept (the B value) based on two points and a slope" << endl
<< "2 to calculate the slope (the M value) based on the Y-intercept and X and Y" << endl <<
"plug-ins" << endl
<< "3 to find the next point up or down a line based on the slope (M) and X and Y"
<< endl << "plug-ins" << endl
<< "4 to find a point x positions down the line based on the slope (M) and X and Y"
<< endl << "plug-ins" << endl
<< "5 to find the equation of a parallel line in form y=mx+c"
<< endl << "plug-ins" << endl;

string selection;
cin >> selection;
if(selection == "0") {
mcalcxyplugin();
i++;
}
else if(selection == "1") {
calcbxymplugin();
i++;
}
else if(selection == "2") {
calcmxybplugin();
i++;
}
else if(selection == "3") {
calcpointxymplugin(1);
i++;
}
else if(selection == "4") {
int a;
cout << "How many points up/down the line do you want? (Positive number for points" << endl
<< "further up, negative for previous points" << endl;
cin >> a;
calcpointxymplugin(a);
i++;
}
else if(selection == "5");{

calcparallelplugin();
i++;
}
else {
i = 1;
}
// End of that loop below
}
return 0;
}

最佳答案

好吧,第一个意味着在main中调用calcparallelplugin(),这是编译器第一次听说此函数的方法。也许您的包含文件中的拼写有所不同?

第二个错误的发生是因为这个流号(分号):

else if(selection == "5");{
                         ^
                         |

那是最后一个“if”的主体,因此终止了语句链;因此,几行后的最后一个“else”与任何先前的“if”都不相关。

关于c++ - 2个小错误,我无法用C++理解!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10376130/

相关文章:

java - "Cannot be applied to given types"打印流期间出错

c - Windows 上的加载程序出现权限被拒绝错误

MATLAB:协方差矩阵的行列式是 0 或 inf

algorithm - 通过添加来自标准基的向量构建满秩矩阵

c++ - C/C++ 中的显式类型转换运算符

c++ - 在位置 X 停止播放来自 QMediaPlayer 的视频

c++ - 嵌套开关给出错误并指示病毒(特洛伊木马)

swift - DGElasticPullToRefresh - 由于信号 : Segmentation fault: 11,命令失败

Python:将矩阵转换为半正定

c++ - 在 Windows 8.1 中模拟按键