generator

Im working on a tutorial from a book that simulates a die roll by generating a random number. The only error i get is 'generator' was not declared in this scope. Am I not including the right header files? Keep in mind I am working in xcode on a mac.




// Die roller
// Demonstrates generating random numbers

#include <iostream>
#include <cstdlib>
#include <ctime>


using namespace std;

int main()
{

srand(static_cast<unsigned int>(time(0))); // seed random number
generator;

int randomNumber = rand(); // generate random number

int die = (randomNumber % 6) + 1; // Get a number between 1 and 6
cout << " You rolled a " << die << endl;

return 0;
}
Last edited on
"generator" is supposed to be part of the comment in the previous line.
closed account (EvoTURfi)
Add a new // for generator to make it a comment. Also, a more compact way of seeding and generating a random number would be:

1
2
3
srand(time(NULL));
int die=rand() %6 +1;
cout<<"You rolled a "<<die<<endl;


This is the same as what you did above, but it is more compact.
Last edited on
hey guys i need help :( please
Athar and davder123 gave you the answers you required. If you don't understand ask a more specific question.
Hey that was my first post and was great help! Thank you for your time =D
Topic archived. No new replies allowed.