why it doesn't give me a random number? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
5th Oct 2023, 3:47 AM
iliass syabri
iliass syabri - avatar
2 Answers
+ 6
iliass syabri , According to your code, The variable `var` is not assigned in any value, so it contains an unpredictable value. For random number, use the `rand()` function.. see this modified version of your code.. https://code.sololearn.com/cy6He3BvcFvC/?ref=app
5th Oct 2023, 4:21 AM
Darpan kesharwani🇮🇳[Inactive📚]
Darpan kesharwani🇮🇳[Inactive📚] - avatar
+ 5
The code you provided doesn’t generate a random number. Instead, it declares an integer variable and prints its value. Since var is not initialized, its value is undefined and can be any garbage value. If you want to generate a random number in C++ See this: https://code.sololearn.com/cU6QfO5ihO3Q/?ref=app
5th Oct 2023, 4:36 AM
Moree
Moree - avatar