+ 1
why it doesn't give me a random number?
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
+ 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