+ 2

Why the rand() only gives output 41?

17th Jul 2017, 3:49 PM
Sritama Kundu
Sritama Kundu - avatar
7 ответов
+ 3
Mind posting your code? Will happily help you with that.
17th Jul 2017, 3:59 PM
AgentSmith
+ 3
You can do something like this, if you want 1 - 10: #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(NULL)); int oneToTen; oneToTen = rand() % 10 + 1; cout << oneToTen; } https://code.sololearn.com/c2cv43zY0Xle/#cpp
17th Jul 2017, 4:12 PM
AgentSmith
+ 1
okk
17th Jul 2017, 4:00 PM
Sritama Kundu
Sritama Kundu - avatar
17th Jul 2017, 4:01 PM
Sritama Kundu
Sritama Kundu - avatar
+ 1
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(NULL)); cout << rand(); }
17th Jul 2017, 4:08 PM
AgentSmith
+ 1
wow thanks
17th Jul 2017, 4:12 PM
Sritama Kundu
Sritama Kundu - avatar
+ 1
You're more than welcome. Hope that helps. Read up on srand when you get time, that'll help out further with it later.
17th Jul 2017, 4:13 PM
AgentSmith