943,746 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 580
  • C++ RSS
Nov 14th, 2008
0

help in c++

Expand Post »
for(i=0;i<9;i++)
{
x[i] = rand()%9+1;
for(j=1;j<9;j++)
{
if(x[i]==x[i-j]);
i--;
}
}

pls tell me how the rand() function work. urgent. as soon as possible.
Last edited by ariesangel; Nov 14th, 2008 at 4:57 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ariesangel is offline Offline
9 posts
since Nov 2008
Nov 14th, 2008
0

Re: help in c++

Click to Expand / Collapse  Quote originally posted by ariesangel ...
pls tell me how the rand() function work.
According to Cplusplus.com, rand() returns a pseudo-random integral number in the range 0 to RAND_MAX. This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using srand.

And that's all you need to know about that.

Now for this:
Click to Expand / Collapse  Quote originally posted by ariesangel ...
urgent. as soon as possible.
If you hadn't waited for the last minute to start your homework, it wouldn't be urgent now would it?

Now next time you post:
- use code tags
- Create a meaningful title
- Ask a clear question
- Don't use words like 'urgent'
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Nov 14th, 2008
0

Re: help in c++

hello. thanxs.
can u pls conform this equation : any no from 0 to 9 are used and after module and add 1 store in x[i]. pls reply.



Click to Expand / Collapse  Quote originally posted by niek_e ...
According to Cplusplus.com, rand() returns a pseudo-random integral number in the range 0 to RAND_MAX. This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using srand.

And that's all you need to know about that.

Now for this:


If you hadn't waited for the last minute to start your homework, it wouldn't be urgent now would it?

Now next time you post:
- use code tags
- Create a meaningful title
- Ask a clear question
- Don't use words like 'urgent'
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ariesangel is offline Offline
9 posts
since Nov 2008
Nov 14th, 2008
0

Re: help in c++

Click to Expand / Collapse  Quote originally posted by ariesangel ...
hello. thanxs.
can u pls conform this equation : any no from 0 to 9 are used and after module and add 1 store in x[i]. pls reply.
Use correct grammar

How to use rand()
Reputation Points: 27
Solved Threads: 3
Light Poster
Grigor is offline Offline
26 posts
since Jan 2007
Nov 14th, 2008
0

Re: help in c++

Click to Expand / Collapse  Quote originally posted by ariesangel ...
hello. thanxs.
can u pls conform this equation : any no from 0 to 9 are used and after module and add 1 store in x[i]. pls reply.
Too vague.

What do you want? Do you want a random number between 0-9 or 1-10? How big is your x[] array? Where do you seed the random generator with srand()?
Last edited by Nick Evan; Nov 14th, 2008 at 5:20 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Nov 14th, 2008
0

Re: help in c++

sorry for the disturb you. but i m big problem.
i make a sudoku game and for that i use this conditon to generate a random no bet o to 9.
i want to conform it takes a value by following code. i m new in programming. and donot know how to do this game. and i have only 4 days to complete it..



Click to Expand / Collapse  Quote originally posted by niek_e ...
Too vague.

What do you want? Do you want a random number between 0-9 or 1-10? How big is your x[] array? Where do you seed the random generator with srand()?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ariesangel is offline Offline
9 posts
since Nov 2008
Nov 14th, 2008
0

Re: help in c++

Click to Expand / Collapse  Quote originally posted by ariesangel ...
sorry for the disturb you. but i m big problem.
i make a sudoku game and for that i use this conditon to generate a random no bet o to 9.
All the sudoku's I've ever played had numbers from 1-9 and not 0-9, but whatever. Here's a small example that gives 1 random number in the range 1-9:
C++ Syntax (Toggle Plain Text)
  1.  
  2. // Seed the generator. Do this ONLY ONCE
  3. srand((unsigned)time(NULL));
  4. cout << (rand() % 9) +1;

Click to Expand / Collapse  Quote originally posted by ariesangel ...
i m new in programming. and donot know how to do this game. and i have only 4 days to complete it..
If you're new in programming and this is your first assignment and you only got 4 days to finish it, you should complain to your teacher, not me.
But I guess that this isn't your first assignment right? And you probably got more then 4 days to finish it, true?
So, again: If you started earlier, you wouldn't have a problem now.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Nov 14th, 2008
0

Re: help in c++

thank u niek for the help. i started this game 3 days ago, but to develop a logic my time is spent. i m not complain to u. and i m not a student i m a flash developer. i m new in development. this is my first task, and that's why i want to do my best to complete it. b'coz first impression is last imperssion.



Click to Expand / Collapse  Quote originally posted by niek_e ...
All the sudoku's I've ever played had numbers from 1-9 and not 0-9, but whatever. Here's a small example that gives 1 random number in the range 1-9:
C++ Syntax (Toggle Plain Text)
  1.  
  2. // Seed the generator. Do this ONLY ONCE
  3. srand((unsigned)time(NULL));
  4. cout << (rand() % 9) +1;



If you're new in programming and this is your first assignment and you only got 4 days to finish it, you should complain to your teacher, not me.
But I guess that this isn't your first assignment right? And you probably got more then 4 days to finish it, true?
So, again: If you started earlier, you wouldn't have a problem now.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ariesangel is offline Offline
9 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC