Arrays and for loops

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2007
Posts: 50
Reputation: guy40az is an unknown quantity at this point 
Solved Threads: 2
guy40az guy40az is offline Offline
Junior Poster in Training

Arrays and for loops

 
0
  #1
Mar 26th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,616
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Arrays and for loops

 
0
  #2
Mar 26th, 2007
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.
Last edited by ~s.o.s~; Mar 26th, 2007 at 2:44 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 50
Reputation: guy40az is an unknown quantity at this point 
Solved Threads: 2
guy40az guy40az is offline Offline
Junior Poster in Training

Re: Arrays and for loops

 
0
  #3
Mar 26th, 2007
Originally Posted by ~s.o.s~ View Post
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



Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,031
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Arrays and for loops

 
0
  #4
Mar 26th, 2007
Originally Posted by guy40az View Post
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 50
Reputation: guy40az is an unknown quantity at this point 
Solved Threads: 2
guy40az guy40az is offline Offline
Junior Poster in Training

Re: Arrays and for loops

 
0
  #5
Mar 26th, 2007
Originally Posted by Aia View Post
D_Nath[i]=PI*D[i]/er[i]*.76554;

You forgot to change the () for [] inside statement inside the loop
Thanks for all your help. it worked great!!.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC