Write a function called nRandomNumbers( ) to perform the following tasks:

1. Generate N random integers between -250 and 250 (inclusive) and save them in a file called number.txt, (Use the function srand()).
2. Print all the generated integers.
3. Compute and return the average of all the negative integers, and the maximum of all the positive integers
I dont know how to use srand function please help me;
I wrote the code but its gives me error

#include<iostream>
#include<cstdlib>
using namespace std;
void nRandomNumbers()
{
	int a;
	

	
	a=srand(250);
	cout<<a;
}


int main ()
{
	

	nRandomNumbers();



	return 0;
}

Recommended Answers

All 3 Replies

Why do you first time posters always leave out the most important information to understanding the problem? The response to the information given:

I wrote the code but its gives me error

That's because you did something wrong.

Don't you think what the error is might be an important piece of information?

Use rand instead of srand. srand is the seed.

int number=250

srand ( (unsigned)time ( NULL ) );
r=rand() % number+1;
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.