| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
A Beginner's Question Part:2
A great big thanks to MichaelSoft whose cleverness saved me hours of frustration and aggervation, however now I have yet another problem. Sometimes (not always) when I try to use simple things like rand, scanf(, and printf( my compiler gives me an error message saying
"`rand' undeclared (first use this function)"Can anyone tell me 1) Why it does this and 2) how to fix it?!? Thanks!!!! |
|
#2
|
||||
|
||||
|
are you forgeting () behind rand? it says first time in function because the compiler sees it as a variable that you havent declared in that code block, but I believe you are actually trying to use the random number generator (right?). But me just a begginer too so hope this helps =Þ
|
|
#3
|
|||
|
|||
|
Quote:
No, I used the (), and yes that is for random number generator. Thanks for your help, though. Any other ideas why it wouldn't work? Thanks! |
|
#4
|
||||
|
||||
|
PreemptFallacy
Well I understand what all those do but your problem is not with those functions its with the way you are using them. When you get an error that is (undeclared,first use in function) it is because like I said you are trying to use an unidentified variable, which means when you see 'rand' undeclared first use in function, you must be trying to use the rand function not scanf or printf or it would say scanf or printf first use in function. So alls I am saying when you get a compile error like that its only because you are trying to use a local variable as a global or you haven't defined it yet, or the variable is in another code block. If you have an example of one of your programs that gives you that error and print the code here I could better explain what I mean if you don't understand what I'm saying. |
|
#5
|
||||
|
||||
|
It could be that you're simply forgetting to include the "stdio.h" and/or "stdlib.h" header files....?
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#6
|
|||
|
|||
|
I do belive your right. I should do something like r=rand() when I declare the rest of my local variables (or global, I guess?)
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > A Beginner's Question Part:2 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|