I have not done any c++ programming yet but was wondering how you use arrays in a for loop for example the code below

int i;
double D_Nath(11),D(11),er(11);
for( i=0;i < 11; i++)
{
D_Nath(i)=PI*D(i)/er(1)*.76554;
}


how dod you get this to work correctly.

Thanks for any help with this.

Recommended Answers

All 4 Replies

Replace the round brackets with square ones [] and you are good to go...Oh and btw it would be a good idea to initialize your arrays.

Replace the round brackets with square ones [] and you are good to go...Oh and btw it would be a good idea to initialize your arrays.

i have tried to change it

int i;
double D_Nath[11],D[11],er[11];
for( i=0;i < 11; i++)
{
D_Nath(i)=PI*D(i)/er(i)*.76554;
}


this is what I have for the code but I am getting a C2064 error in the line with the D_Nath(I)=
any idea what I am doing wrong

i have tried to change it

int i;
double D_Nath[11],D[11],er[11];
for( i=0;i < 11; i++)
{
D_Nath(i)=PI*D(i)/er(i)*.76554;
}

this is what I have for the code but I am getting a C2064 error in the line with the D_Nath(I)=
any idea what I am doing wrong

D_Nath[i]=PI*D[i]/er[i]*.76554;

You forgot to change the () for [] inside statement inside the loop

`D_Nath[i]=PID[i]/er[i].76554;

You forgot to change the () for [] inside statement inside the loop

Thanks for all your help. it worked great!!.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.