944,201 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1520
  • C++ RSS
Mar 26th, 2007
0

Arrays and for loops

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
guy40az is offline Offline
51 posts
since Mar 2007
Mar 26th, 2007
0

Re: Arrays and for loops

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.
Super Moderator
Featured Poster
Reputation Points: 3244
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Mar 26th, 2007
0

Re: Arrays and for loops

Click to Expand / Collapse  Quote originally posted by ~s.o.s~ ...
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



Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
guy40az is offline Offline
51 posts
since Mar 2007
Mar 26th, 2007
0

Re: Arrays and for loops

Click to Expand / Collapse  Quote originally posted by guy40az ...
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
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Mar 26th, 2007
0

Re: Arrays and for loops

Click to Expand / Collapse  Quote originally posted by Aia ...
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!!.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
guy40az is offline Offline
51 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: password input
Next Thread in C++ Forum Timeline: Waitkey command





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC