Question:
C++ Help! Why is the identifier undeclared?
jem5218
2007-10-30 17:26:13 UTC
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
using namespace std;

int main()
{
const int TOTALNUMBERS = 10;
int numbers[TOTALNUMBERS];

// Read all numbers
for (int i = 0; i < TOTALNUMBERS; i++)
{
cout << "Enter a number: ";
cin >> numbers[i];
}
//Find numbers divisible by 3
int div = 0;
for (int i = 0; i < TOTALNUMBERS; i++);
{
if ((numbers[i] % 3)==0)
div++;
}
cout << "Numbers divisible by three: " << div <
return 0;

}
Five answers:
MistWing
2007-10-30 17:46:34 UTC
You have a semicolon at the end of the for statement. This 'closes' the for loop and its associated 'i' is dropped.
?
2016-11-10 02:10:13 UTC
supply this a attempt... as a substitute of employing the variety... int ArrayName[] = { 0, 0, 0, 0 }; attempt unquestionably allocating each and every element in my opinion... int ArrayName [ 4 ]; ArrayName [ 0 ] = a million; ArrayName [ a million ] = 2; ...and so forth. i've got run into a matching situation in the past and ended up merely allocating each and every element in my opinion to get previous the computer virus.
anonymous
2007-10-30 17:46:36 UTC
for (int i = 0; i < TOTALNUMBERS; i++);



theres a semicolon at end of second for loop where there shouldn't be one
?
2007-10-30 17:42:00 UTC
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
xanqui1293
2007-10-30 17:58:14 UTC
It is a semi-colon at the end of your loop that should not be there.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...