+ 2
Why the rand() only gives output 41?
7 ответов
+ 3
Mind posting your code? Will happily help you with that.
+ 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
+ 1
okk
+ 1
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(NULL));
cout << rand();
}
+ 1
wow thanks
+ 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.