GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-May-2004, 10:19
Shufty Shufty is offline
New Member
 
Join Date: May 2004
Posts: 14
Shufty is on a distinguished road

Outputting function result to an array


Hi, I'm trying to generate a random number and output the result to the first part of an array, then a new random number to the second part etc.
Here's the code for the random number I'm using (the appropriate headers are being used too)

int random_number;
srand((unsigned int)time((time_t *)NULL));
random_number = (rand()%49)+1;

I want to output the result of this into an array called winning[n]

Any help anyone can give would be greatly appreciated!
  #2  
Old 07-May-2004, 11:04
tay's Avatar
tay tay is offline
Junior Member
 
Join Date: Jan 2004
Posts: 77
tay will become famous soon enough
1st i duno how much size u need for ur winning[n] array,
so i simply assign n=49;

CPP / C++ / C Code:
int main()
{
int random_number;
srand((unsigned int)time((time_t *)NULL));
//random_number = (rand()%49)+1;

const int n = 49;// i don't know wht size u need for u winning[n]
// so i simply put 49
int winning[n];

for ( int i =0; i<n; i++ )
{
winning[i]=(rand()%49)+1;// generate random num for ur winning[n]
cout<<winning[i]<<endl;
}

Last edited by dsmith : 07-May-2004 at 11:28. Reason: Fixed highlighting
  #3  
Old 07-May-2004, 11:28
Shufty Shufty is offline
New Member
 
Join Date: May 2004
Posts: 14
Shufty is on a distinguished road
thanks! I'll let you know if I can get it to work with the rest of my code (I'm not very good at this stuff) ??:
  #4  
Old 07-May-2004, 11:43
tay's Avatar
tay tay is offline
Junior Member
 
Join Date: Jan 2004
Posts: 77
tay will become famous soon enough
Quote:
Originally Posted by Shufty
thanks! I'll let you know if I can get it to work with the rest of my code (I'm not very good at this stuff) ??:


as long as you have try it,
you will get improvement

at 1st everyone at here also not well at c/c++
all those things is u need more pratical
the more u code, the more you will learn
__________________
challenges are make life interesting,
overcome them is make life meaningful.
  #5  
Old 07-May-2004, 11:45
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Shufty
Hi, I'm trying to generate a random number and output the result to the first part of an array, then a new random number to the second part etc.
Here's the code for the random number I'm using (the appropriate headers are being used too)
CPP / C++ / C Code:
int random_number;
srand((unsigned int)time((time_t *)NULL));
random_number = (rand()%49)+1;
I want to output the result of this into an array called winning[n]

Any help anyone can give would be greatly appreciated!

Let's simplify:
CPP / C++ / C Code:
srand(time(NULL));  // call ONLY ONCE in the program
winning[n] = (rand()%49)+1;
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting elements of arrays C++ the_crazyman C++ Forum 25 30-May-2008 08:27
Help with array and function input FearlessFife35 C Programming Language 13 16-Apr-2004 15:10
Revising Script style ?????? pepee MySQL / PHP Forum 4 14-Apr-2004 05:59
Speed up C++ code about 3d array! Truong Son C++ Forum 0 16-Mar-2004 22:52
throwing an struct(with an array) through a function knakworstje C Programming Language 5 15-Feb-2004 17:20

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:25.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.