TOG
Member
- Jul 9, 2013
- 4,169
- 793
I'm trying to learn C++. I'm using the book C++ Without Fear by Brian Overland and I have Code::Blocks as my programming environment. Here are some parts of the program that isn't working. It starts out fairly normally...
So far so good. The program is supposed to pick random numbers. It starts by setting a seed.
Later in the program, it has a function that picks the number. The function contains just one line, which picks a random number from 0 to 9 and returns it to the function that called it.
#include<iostream>
#include<cmath>
#include<ctime>
using namespace std;
#include<cmath>
#include<ctime>
using namespace std;
So far so good. The program is supposed to pick random numbers. It starts by setting a seed.
srand(time(null));
Later in the program, it has a function that picks the number. The function contains just one line, which picks a random number from 0 to 9 and returns it to the function that called it.
return rand() % 10;
When I try running this, both lines give me errors saying that the srand and rand functions haven't been declard and also that null had not been declared. I imagine that the version of C++ I have is slightly different from what the author of the book had. I've tried googling it, but the sites I found said the same as the book. Are there any C++ geniuses here that see what I'm missing?
The TOG