Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,230 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,092 people online right now. Registration is fast and FREE... Join Now!




Random Number conflict

 
Reply to this topicStart new topic

Random Number conflict

ifsogirl
post 15 Mar, 2008 - 05:50 AM
Post #1


New D.I.C Head

*
Joined: 15 Mar, 2008
Posts: 18


My Contributions


One problem to the next, right? I can only hope that the reply to this will be a swift and helpful as the reply to the last was.

Okay, once again, I'll try to explain my self, so here goes. I have to include a random number in this game. I chose to make the number of years a random number. I did this:
CODE

cout<<"Arcan, your friend for the last " srand(time(NULL));
cout <<  rand() % 5 + 1 << " years tells you the city gives him the creeps."<<endl;

which I got following a tutorial on D.I.C... about, oh, maybe half an hour ago. I don't know what I did wrong, but it keeps telling me this: error C2146: syntax error : missing ';' before identifier 'srand'
I'll admit it freely; I'm an idiot at coding. I have no idea what that means. Where am I supposed to put a semicolon before srand if I'm using it to cout information?
User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 15 Mar, 2008 - 05:56 AM
Post #2


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


The error is exactly mentioning what you have missed.

This is what you have:
cout<<"Arcan, your friend for the last " srand(time(NULL));

You do know that cout and srand are two different statements :)

So there should be a semi-colon at the end of the cout statement even if you want to put them both on the same line.

cout<<"Arcan, your friend for the last " ; srand(time(NULL));

Hope that helps
User is offlineProfile CardPM

Go to the top of the page

ifsogirl
post 15 Mar, 2008 - 06:01 AM
Post #3


New D.I.C Head

*
Joined: 15 Mar, 2008
Posts: 18


My Contributions


wahh, I was just about to come and say to disregard that... I messed around with the code a bit and finally got it to work. Thank you though; I did exactly what you said, after thinking about how code works. I feel so stupid, though, haha.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 09:24PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month