0

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;
}
4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by alexchen
0

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?

Edited by WaltP: n/a

0

Use rand instead of srand. srand is the seed.

int number=250

srand ( (unsigned)time ( NULL ) );
r=rand() % number+1;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.