Tuesday, July 14, 2009

C++ Help! Why is the identifier undeclared?

Ok... I have this code that I wrote that takes 10 numbers and outputs the amount divisible by 3, but the one and only error message reads that 'i' in line 18 is an undeclared integer. What do I need to do to fix this? Here's the code. Thanks guys.





#include %26lt;iostream%26gt;


using namespace std;





int main()


{


const int TOTALNUMBERS = 10;


int numbers[TOTALNUMBERS];





// Read all numbers


for (int i = 0; i %26lt; TOTALNUMBERS; i++)


{


cout %26lt;%26lt; "Enter a number: ";


cin %26gt;%26gt; numbers[i];


}


//Find numbers divisible by 3


int div = 0;


for (int i = 0; i %26lt; TOTALNUMBERS; i++);


{


if ((numbers[i] % 3)==0)


div++;


}


cout %26lt;%26lt; "Numbers divisible by three: " %26lt;%26lt; div %26lt;%26lt;endl;





return 0;





}

C++ Help! Why is the identifier undeclared?
You have a semicolon at the end of the for statement. This 'closes' the for loop and its associated 'i' is dropped.
Reply:It might be that since you already declared i in the other for loop, try taking off the int.


for( i=0;





I see nothing else
Reply:It is a semi-colon at the end of your loop that should not be there.
Reply:for (int i = 0; i %26lt; TOTALNUMBERS; i++);





theres a semicolon at end of second for loop where there shouldn't be one

online survey

No comments:

Post a Comment