0

How to make my car move only by 1 and not by a random number (solved)

Race car https://code.sololearn.com/ctTv2bhG37ly/?ref=app

12th May 2021, 3:15 AM
Joshua
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?
12th May 2021, 5:32 AM
XXX
XXX - avatar
+ 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
12th May 2021, 3:56 AM
XXX
XXX - avatar
+ 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.
12th May 2021, 4:49 AM
XXX
XXX - avatar
+ 2
That's strange. GCC always shows "No such file or directory" when I include <conio.h>.
12th May 2021, 5:24 AM
XXX
XXX - avatar
+ 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.
12th May 2021, 5:28 AM
XXX
XXX - avatar
+ 1
Have u tried reinstalling it?
12th May 2021, 5:26 AM
Joshua
0
Im using codeblocks is that a good compiler or what
12th May 2021, 4:04 AM
Joshua
0
Yes it works. My compiler is gnu gcc
12th May 2021, 5:04 AM
Joshua
0
Oh yahh it shows conio.h with an error but i dont know why it works on my laptop
12th May 2021, 5:34 AM
Joshua