#include <iostream>
#include <iomanip> //round numbers
#include <cstdlib>
using namespace std;
int main( )
{
//Declare
const double ONE_COOKIES = 75.0;
double ATE_COOKIES;
double TOTAL_CALORIES;
//Output of program
cout << " Input how many cookies you ate (eg, 3 & 5): " << endl;
cin >> ATE_COOKIES;
// Round numbers
cout << fixed << setprecision(1) << ATE_COOKIES << endl;
//Formula
double TOTAL_CALORIES = ATE_COOKIES * ONE_COOKIES;
//Results
cout << " One cookie is equal to " << ONE_COOKIES << " caloreis " << " And you ate " << double caloreis << " of cookies" << endl;
system ("pause");
return 0;
}
这是一个 C++ 程序,我试图计算该程序。我在计算程序时遇到问题,所以我正在寻求帮助。提前致谢。
最佳答案
您不能重新申报 TOTAL_CALORIES。 double
标识符仅用于创建变量的原因。
语句应该是TOTAL_CALORIES = ATE_COOKIES * ONE_COOKIES;
因为你只是给TOTAL_CALORIES
赋值,而不是声明变量。
这似乎也适用于您的 cout 语句,当您只是使用您不需要需要指定它的类型的变量时,您告诉编译器一次,这就是您需要做的全部。
int thing = 0;
thing = 4; //just assign a value
cout << thing << endl; //print the value
另一方面,您应该避免在变量中使用全部大写。这通常表示程序中的常量。尝试使用驼峰式或全部小写命名可变变量。
关于C++ 错误 : Redeclaration of double TOTAL_CALORIES previously redclare here,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26836011/