我对C++非常新颖,我只是写了这个代码,要求你输入,并且它变成了变量,经历了计算,并给出了输出。我得到的编译错误说'int ns'和'int sum'是无效的。编译错误? (C++)
#include <iostream>
int main() {
sum = ns - 2 * 180;
std::cout << "Enter the number of sides";
int ns;
int sum;
std::cin >> ns;
sum = ns * 180 - 360;
std::cout << "The sum of all of the interior angles is" << sum;
system("PAUSE");
}
有人可以告诉我这里的错吗?
你在'总和= NS使用一个未定义的类型 - 2 * 180;'你需要移动的声明更高,从而移动'诠释NS和上面那行sum'诠释 – EdChum
你在哪里声明'ns'和'sum'?你先在哪里使用它们? – Elried
你也可以使用'std :: cin >> ns;'然后在你的第一行上尝试一下操作,这是没有意义的 – EdChum