i need to write a program that ouputs any five positive integers to the screen?

for (int i = 1; i <= 5; i++)
    cout << rand () // what goes here?

usually when there's a range (lets say any 3 digit number) i usually do it like this

cout << rand() % 900 + 100 << endl;

but i need to include any positive integer (so no range??) in my code. how do i do it?

Also what would you do to print any negative number?

Simply using rand() should be producing positive integers between 0 and RAND_MAX. If you want to print negative numbers you could still use rand() and then multiply it by 1.

for starts have you seeded rand(); I include time and use the very second in time the seed is set as the seed. This will let the rand() statment seem more random. without seeding it you will get the same numbers every time the program is ran.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.