I am writing this code to solve an array problem but i keep getting errors.
i want to declare that pi[0] = [1,0,0,0,0] but it keeps giving me an error. I am trying to declare that because i want to evaluate pi[n] = (pi[n-1]) * 3 for a set of n numbers until pi[n] - pi[n-1] <= 200
I used the for loop insde because i want n to increase and put it in the do while loop so i can tell it to stop.
PLease help..... what am i doing wrong?
double pi[0] is an array of zero doubles. What's that supposed to mean? If you want an array of 5 values initialised to (1,0,0,0,0) then it's
double a[] = {1,2,3,4};
You need {...} to delimit the scope of the for () loop
i.e.
for( n = 1 ; n > 100 ; n++ )
{
.... do stuff
}
You can't declare an array variable with a dynamic size (i.e. from a variable), so double pi[n] isn't valid.
Use new instead.
Something like double *pi = new double[n]
..use it, then
delete [] pi;
You're also hiding the original pi variable by your second declaration
... IN general there's lots of other guff wrong, too. You're kind of on the wrong track here.
I presume this is homework?
0
mrperfect75000Author Commented:
Yes it is, If i can correct those errors i will give it a shot again...Thanx for the direction....is there a better way to go about this? I'm really lost
Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
pi is a 5 element array. but since i know p[0] and a formula for p[n] i want to computer values for
p[n] for n up to a certain number. doesnt matter what this number is as far as a get a couple of values for p[n].
pi[n-1] * 3: I want n to keep increasing starting from n = 1. I want 5 values [1,0,0,0,0] initialised in pi[0]. so that when n = 1, ........ pi[n-1] = p[0]. then i want to assing p[n] to equal p[n-1] multiplied by 3.
I think you want to generate pi as 1,3,9,27,81 . . . where p[n]=p[n-1]*3 and p[0]=1. See in the following sample of code to generate numbers up to 5 terms
#include <iostream>
using namespace std;
const int M = 5;
int main()
{
int n;
double pi[M];
Strangely enough I could have written that code, too, Smpoojary. But this is a homework question, and you don't answer homework questions verbatim on EE.
0
mrperfect75000Author Commented:
Thanks Guys.
What i am trying to do is this....I understand the concept i just cannot code it in C++ ...i dont know what i am missing.
ok....
pi(0) = [1,0,0,0,0] that is a row vector.
n can be a number 1,2,3,..........i want it to increase.
double a[] = {1,2,3,4};
You need {...} to delimit the scope of the for () loop
i.e.
for( n = 1 ; n > 100 ; n++ )
{
.... do stuff
}
You can't declare an array variable with a dynamic size (i.e. from a variable), so double pi[n] isn't valid.
Use new instead.
Something like double *pi = new double[n]
..use it, then
delete [] pi;
You're also hiding the original pi variable by your second declaration
... IN general there's lots of other guff wrong, too. You're kind of on the wrong track here.
I presume this is homework?