help in c++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 9
Reputation: ariesangel is an unknown quantity at this point 
Solved Threads: 0
ariesangel ariesangel is offline Offline
Newbie Poster

help in c++

 
0
  #1
Nov 14th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,889
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 302
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac

Re: help in c++

 
0
  #2
Nov 14th, 2008
Originally Posted by ariesangel View Post
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:
Originally Posted by ariesangel View Post
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'
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 9
Reputation: ariesangel is an unknown quantity at this point 
Solved Threads: 0
ariesangel ariesangel is offline Offline
Newbie Poster

Re: help in c++

 
0
  #3
Nov 14th, 2008
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.



Originally Posted by niek_e View Post
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'
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 25
Reputation: Grigor is an unknown quantity at this point 
Solved Threads: 3
Grigor's Avatar
Grigor Grigor is offline Offline
Light Poster

Re: help in c++

 
0
  #4
Nov 14th, 2008
Originally Posted by ariesangel View Post
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()
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,889
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 302
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac

Re: help in c++

 
0
  #5
Nov 14th, 2008
Originally Posted by ariesangel View Post
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 niek_e; Nov 14th, 2008 at 5:20 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 9
Reputation: ariesangel is an unknown quantity at this point 
Solved Threads: 0
ariesangel ariesangel is offline Offline
Newbie Poster

Re: help in c++

 
0
  #6
Nov 14th, 2008
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..



Originally Posted by niek_e View Post
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()?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,889
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 302
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac

Re: help in c++

 
0
  #7
Nov 14th, 2008
Originally Posted by ariesangel View Post
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:
  1.  
  2. // Seed the generator. Do this ONLY ONCE
  3. srand((unsigned)time(NULL));
  4. cout << (rand() % 9) +1;

Originally Posted by ariesangel View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 9
Reputation: ariesangel is an unknown quantity at this point 
Solved Threads: 0
ariesangel ariesangel is offline Offline
Newbie Poster

Re: help in c++

 
0
  #8
Nov 14th, 2008
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.



Originally Posted by niek_e View Post
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:
  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC