<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. 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];
and where you assign your array eg 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.