#include <cstdlib>
#include <iostream>
int GenerateID()
{
using namespace std;
static int nNextID = 0;
nNextID++;
if (nNextID <= 20)
cout << nNextID << endl;
}
int main()
{
int GenerateID();
system("pause");
}
why isn't the above program running? I want it to generate on the console numbers from 1-20 with this program.
In fact, the program is running. However, the program is not generating any output. I expect the output to be the numbers 1 to 20 on one line separated by a space. I observe blank, i.e. no output.
The program does not crash. There are no compiler errors or warnings. In fact, here is a walk-through of the program:
I import two libraries, cstdlib for executing system commands using system and iostream for the input and output objects cin and cout, respectively. They're located in the std namespace so I type using namespace std because I'm lazy and don't want to type std::cout.
Then I initialize nNextID to 0, increment it, and if it's less than 20 it shall output nNextID. This is the end of the function.
I call that function from main and use pause to end the program. So, why do I get blank output when I am expecting 1 to 20 on a line, numbers delimited by spaces?