'result' not declared in this scope

Am using 'Code Blocks' 10.05 on a windows 7 pc to follow the cplusplus language tutorial. Entered the second project 'operating with variables' exactly as written but it won't run. I am not sure why but here it is:


//Operating with variables
#include <iostream>
using namespace std;
int main ()
{
//declaring variables
int a, b;
//process or operation/algorithm
a = 5;
b = 2;
a = a + 1;
result = a - b;
//print out the result:
cout << result;
//end the program
return 0;
}


When I run it, line 12 shows:
error: 'result' was not declared in this scope

I'm not sure what this means or how to fix it? Any help is greatly appreciated. Thanks!

It's what the error says, you didn't declare 'result'
And please use [code][/code] tags when posting code
OK-Sorry about the tags. I went back over the lesson in the tutorial and it looks like the author says that 'result = a - b;' is declaring result. How else would I declare it other than the manner listed in the tutorial? Thanks!
http://www.cplusplus.com/doc/tutorial/variables/ Scroll to Declaration of variables

BTW Here is the code example from there:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// operating with variables

#include <iostream>
using namespace std;

int main ()
{
  // declaring variables:
  int a, b;
  int result;

  // process:
  a = 5;
  b = 2;
  a = a + 1;
  result = a - b;

  // print out the result:
  cout << result;

  // terminate the program:
  return 0;
}
Last edited on
Thank you! I can't believe I missed it!
Topic archived. No new replies allowed.