can u pls explain to me the use pf srand function & its syntax?i tried the following coding.it compiled,but runpage is not getting displayed.

#include<iostream.h>
#include<stdlib.h>
int randomno();
int main()
{    
 int i; 
   
 cout<<"ten random numbers for the range 0 to 50"<<endl;   
 for(i=0;i<10;i++)   
 {      randomno();     }   
return o;} 
int randomno()
{    int j;
    j = rand();     
 if (!(j >= 50&&j<=0))
   cout<< j<<endl; 
else
cout<<"out of range"<<endl;
return 0;
}

Recommended Answers

one thing,
return 0 from main not 'o' (not o)
your code will work

try this

j = rand()%50;

and replace your condition

if (!(j >= 50&&j<=0))
cout<< j<<endl; 
else
cout<<"out of range"<<endl;

and only print the j
what is does ? requires …

Jump to Post

All 2 Replies

one thing,
return 0 from main not 'o' (not o)
your code will work

try this

j = rand()%50;

and replace your condition

if (!(j >= 50&&j<=0))
cout<< j<<endl; 
else
cout<<"out of range"<<endl;

and only print the j
what is does ? requires minute mathematics.

why did you put a return in the middle of main() ? Lines 12-19 will never get executed because of that unconditional return on line 11. Just delete line 11 and the reset will be executed.

Be a part of the DaniWeb community

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