I'm new to programming and have been happily working my way through C++ A Beginner's Guide (which I'm thoroughly enjoying!). However, I've come across a bit of an issue. In chapter 5, Schildt talks about global variables and he presents this small program to show how they could be used:
#include <iostream>
using namespace std;
void func1();
void func2();
int count;
int main()
{
int i;
for (i = 0; i < 10; i++){
count = i * 2;
func1();
}
cin.get();
return 0;
}
void func1()
{
cout << "count: " << count; // Access global count
cout << "\n";
func2();
}
void func2(){
int count;
for (count = 0; count < 3; count++)
cout << ".";
}
When I compile the code, I'm presented with an error message whenever the variable count is used within the main block and other functions of the program. Is this an issue with the compiler (Visual Studio Express 2013? Do I need to prefix the global variable with something so that it can be used?