Unsure about error

Going over a program in a book to learn FOR loops. Just a basic counting program. For some reason I am getting error C2065 'i': undelcared identifier/IntelliSense: identifier "i" is undefined. It works for the first 2 in the code but the third one isnt working. When I take out that part of the code the program still doesnt work. I feel like I am missing something but dont really know what. Any thoughts?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>

using namespace std;

int main()
{
	cout << "Counting Forward:\n";
	for (int i = 0; i < 10; ++i)
	{
		cout << i << " ";
	}
	cout << "\n\nCounting Backward:\n";
	for (int i = 9; i >= 0; --i)
	{
		cout << i << " ";
	}
	cout << "\n\nCounting by fives:\n";
	for (int i = 0; i <= 50; i += 5);
	{
		cout << i << " ";
	}
	cout << "\n\nCouting with null statements:\n";
	int count = 0;
	for (; count < 10;)
	{
		cout << count << " ";
		++count;
	}
	cout << "\n\nCounting with nested for loops:\n";
	const int ROWS = 5;
	const int COLUMNS = 3;
	for (int i = 0; i < ROWS; ++i)
	{
		for (int j = 0; j < COLUMNS; ++j)
		{
			cout << i << "," << j << " ";
		}
		cout << endl;
	}
	return 0;
}
Line 17: You have a ; at the end of the line. That terminates the for loop, causing i to be out of scope at line 20. Remove the ;

Dude! I spent so much time going over that and missed it every time. LMAO. Thank you so much. I am such a noob. Thanks again.
That being said it still doesn't run. I get this:
'CounterProgram.exe' (Win32): Loaded 'C:\Users\Houston\Desktop\C++ Projects\CounterProgram\Debug\CounterProgram.exe'. Symbols loaded.
'CounterProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'CounterProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'CounterProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'CounterProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Cannot find or open the PDB file.
'CounterProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Cannot find or open the PDB file.
The thread 0x15e0 has exited with code 0 (0x0).
The thread 0x2960 has exited with code 0 (0x0).
The thread 0x3670 has exited with code 0 (0x0).
The program '[14860] CounterProgram.exe' has exited with code 0 (0x0).

Any idea?
Last edited on
line 18 semicolon, take it out. you are done.
I took out the semicolon AbstractionAnon suggested but I got that error I posted earlier.
have you compiled anything other than this program before?
It ran just fine for me.
However, I added after line 39:
 
  system ("pause");


Your program is probably running, but the console window is closing quickly.
See the following sticky thread:
http://www.cplusplus.com/forum/beginner/1988/

The "Cant't find PDB file" messages are normal if you don't have the Windows SDK.




yeah but for the system command he needs to add the library <cstdlib>
Anyways just add the #include <cstdlib> in the beginning and add the system ("pause"); at the end of your code instead of return 0;

I have compiled other programs. Many. I am 1/4 through the book. (not saying that to sound snarky, just to give an idea of how man). I added your suggestion and the pause worked perfectly. I guess it was just running so fast I thought it was bugging. Thank you to everyone for your help. Another not is, just to see what happened I didnt add the library and it still worked. It also worked with the library so that didnt break anything. Just thought I would let everyone know what I did. Thank you again! So helpful and GREATLY appreciated. *hope I spelled that right* <bad english
Psalazar wrote:
add the system ("pause"); at the end of your code instead of return 0;

Not to argue the issues of using system("pause");, but you should have both.
The system call will return, therefore the program should issue a return 0 to return control to the OS.

The newer C++ specifications stipulate that the compiler must provide a return 0; if the user does not provide one, but IMO, it is still a good practice to provide the return 0. The OP does not indicate if he is running on a newer compiler or not.
Last edited on
AbstractionAnon you are probably right =)
Topic archived. No new replies allowed.