简体   繁体   English

数组饼的大小具有非整数类型的“ double”错误,

[英]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.

相关问题 错误:数组&#39;u&#39;的大小具有非整数类型&#39;double&#39;| - error: size of array ‘u’ has non-integral type ‘double’| c ++ map stl错误:数组&#39;apn2policy&#39;的大小具有非整数类型&#39;const char [13]&#39; - c++ map stl error : size of array 'apn2policy' has non-integral type 'const char [13]' 表达式必须具有整数或无作用域的枚举类型 - Expression must have intergral or unscoped enum type 创建类数组时 -&gt; 的基本操作数具有非指针类型错误 - Base Operand of -> has non-pointer type error when creating an array of classes 错误:在…中的成员&#39;end&#39;请求是非类类型&#39;double&#39;的 - error: request for member ‘end’ in … which is of non-class type ‘double’ 我将10测试为数组大小时出现双倍或免费损坏错误 - double or free corruption error when I test 10 as size of an array 错误2296:&#39;^&#39;:非法,左操作数的类型为&#39;double&#39; - error 2296: '^' : illegal , left operand has type 'double' 接受任何大小的 char 的 std::array 作为非类型模板参数 - Accepting std::array of char of any size as non type template parameter 动态数组的两倍大小 - Double size of dynamic array 错误C2297:&#39;&lt;&lt;&#39;:非法,右操作数的类型为&#39;double&#39; - error C2297: '<<' : illegal, right operand has type 'double'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM