0
How to make my car move only by 1 and not by a random number (solved)
9 Answers
+ 3
See this
https://en.m.wikipedia.org/wiki/Conio.h
It says that is not part of the standard and also that "most C compilers that target UNIX and Linux do not have this header and do not supply the library functions". So I'm thinking maybe it exists on windows?
+ 3
If you've made the code yourself, you should know.
The only place I see where you're adding to an element of the 'cars' array is line 62.
`cars[i] += plus;`
As 'plus' holds a random value (assigned in the rands() function), it will move car by a random value.
Just change 'plus' to 1
`cars[i] += 1;`
Also, having global values is generally not a good idea. Passing the values as arguments or using return values directly is a better idea (mostly)
Finally, I hope you know <conio.h> is an obsolete header file from Turbo C, which is not available woth mordern compilers. So I suggest you stop using that
+ 2
Joshua
Codeblocks is not a compiler. It is an IDE.
You can check which compiler codeblocks is using. Go to Settings > "Compiler and Debugger". Under the "Selected Compiler" field, you will see the compiler you're using.
Also, is your program working when you compiler it in codeblocks? Because <conio.h> shouldn't work unless you're using the Turbo C++ compiler, which I highly doubt will work on your machine.
+ 2
That's strange. GCC always shows "No such file or directory" when I include <conio.h>.
+ 2
No, I don't need to. That's actually the correct thing. The <conio.h> header is obsolete. Try running the code on SoloLearn also, it will show error when you include <conio.h>. I'm confused why it is working for you.
+ 1
Have u tried reinstalling it?
0
Im using codeblocks is that a good compiler or what
0
Yes it works. My compiler is gnu gcc
0
Oh yahh it shows conio.h with an error but i dont know why it works on my laptop