我目前已设置,使值,r = 10
。然后,我使用r
对其他变量执行一些计算,然后在第一个system("Pause")
后更改r
(未显示)的值,并期望我之前计算的变量得到更新,但它们不是。一旦r
已更新,如何更新多个变量(calcArea
等)?C++:“如何更改一个变量后,它已经是int”
int r = 10, pi = 3.14, calcArea = 0, calcCircumfrence = 0, calcDiameter = 0;
int main() {
calcArea = pi*r*r;
calcCircumfrence = 2 * pi*r;
calcDiameter = 2 * r;
cout << "Area: " << calcArea << endl;
cout << "Diameter: " << calcDiameter << endl;
cout << "Circumfrence " << calcCircumfrence << endl;
system("Pause");
// Once I've updated r, why haven't these variables changed?
cout << "Area: " << calcArea << endl;
cout << "Diameter: " << calcDiameter << endl;
cout << "Circumfrence " << calcCircumfrence << endl;
system("pause");
// The system follows PEMDAS on point
return 0;
}
这是怎么回事任何与'calcArea'或'calcDiameter'做的不同?你不明白什么?你甚至不试图将其改变为不同的值。 – Tas
欢迎来到Stack Overflow。请花些时间阅读[The Tour](http://stackoverflow.com/tour),并参阅[帮助中心](http://stackoverflow.com/help/asking)中的资料,了解您可以在这里问。 –
这是重读您的编程文本早期章节的好时机。看起来你错过了几个基本概念。如果你没有编程文本,[在这里推荐几个](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)。 – user4581301