Ok so i trying to create a random number generator, to generate random lotto numbers, but when i run the program i get the same number for all 5 here is the code i have so far:
//Random number generator for the lottery
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int regNum(int);
int main()
{
char answer;
cout<<" This a Random Lottery Number Generator \n Would you like to continue ? ";
cin>>answer;
if(answer=='Y' || answer=='y')
{
cout<<" Its good that you choose to continue. \n Here are your Regular Numbers";
//displays 5 random numbers for user to apply to lottery
for( int i=0;i<5;i++)
{
cout<<regNum(time(0))<<" ";
}
}else cout<<"Have a good day \n Press Enter to exit.\n \n";
exit(1);
return 0;
}
int regNum(int num )
{
int regNUM;
srand(num);
regNUM=(rand()%56)+1;
return regNUM;
}
can anyone show me the way to 5 different numbers.
//Random number generator for the lottery
#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int regNum();
int main()
{
srand(time(0));
char answer;
cout<<" This a Random Lottery Number Generator \n Would you like to continue ? ";
cin>>answer;
if(answer=='Y' || answer=='y')
{
cout<<" Its good that you choose to continue. \n Here are your Regular Numbers";
//displays 5 random numbers for user to apply to lottery
for( int i=0;i<5;i++)
{
cout<<regNum()<<" ";
}
}
else
{
cout<<"Have a good day \n Press Enter to exit.\n \n";
}
exit(1);
return 0;
}
int regNum()
{
int regNUM;
regNUM=(rand()%56)+1;
return regNUM;
}
I just learned how to do that a couple of hours ago.
The code is pretty much the same that peter87 wrote.
But if you would like for it to be explained in a video I wil ref you to where i learned it.
There's some very good tuts for beginners like me.
aww man thanks peter that was good stuff i was under the impression you have to pass something to function definition from the function call. now i know better