[英]size of array pie has non-intergral type 'double' error,
<double c, six, part1, part2, part3, part4,part5;
long double pi;
cout << "enter a number: ";
cin >> c;
for(double i = 0; i < c; i++)
{
part1 = (1/(pow(16 ,(double)i)));
part2 = 4/(((8*i))+1);
part3 = 2/(((8*i))+4);
part4 = 1/(((8*i))+5);
part5 = 1/(((8*i))+6);
pi = ((part1)*(part2 - part3 - part4 - part5));
for(int ii = 0; ii < c; ii++)
{
int pie[i] = pi;
}
cout << pi << "\n";>
For some reason i cant store my values in the array please help! 由于某些原因,我无法将我的值存储在数组中,请帮忙! i dont know if its initialzation errors or conversion errors or what.
我不知道它的初始化错误或转换错误或什么。
Ok sorry about that i fixed it didnt notice i diddnt place a second i in the array now its giving me variable size initalization errors. 好的,对此我感到抱歉,它没有注意到我没有在阵列中放置第二个I,现在它给了我可变的大小初始化错误。 any way around that?
有什么办法吗?
I think you mean 我想你是说
pie[i] = pi;
instead of 代替
int pie[i] = pi;
However you still have to declare pie somewhere. 但是,您仍然必须在某个地方声明派。 And the logic of your code is a bit confusing to me so I'm not sure what else to suggest.
而且您的代码逻辑对我来说有些混乱,因此我不确定还有什么建议。
But anyway you have to understand the difference between where you declare your array eg int pie[100];
但是无论如何,您都必须了解声明数组的位置之间的区别,例如
int pie[100];
and where you assign your array eg pie[i] = pi;
以及分配数组的位置,例如
pie[i] = pi;
. 。 These are two different things.
这是两件事。
for(int ii = 0; ii < c; ii++)
{
pie[ii] = pi; // not pie[i],since its in the loop with iterator ii
}
This helps? 这有帮助吗?
With pie[i]
the outer loop value of i
is used. 与
pie[i]
的外环值i
被使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.