0
How I can put output from rand() to X?
I want to make sorta Horoscope but I don't know how to write rand() output into x. How can I do it?
20 odpowiedzi
+ 1
i think this is what you wanted
https://code.sololearn.com/c5L06rLs94SD/?ref=app
+ 1
Sreejith it really doesn't.
0 refers to integral value while null refers to unknown which means that we don't know the value.
+ 1
Sreejith yeah! It's what I needed. lol I dumb cus not tried this
0
x = rand()
is that what you wanted??
0
I tried do it. It's not working
0
show your code
0
I can't do it rn. Maybe later ok?
0
sure
0
auto x = std::rand();
make sure to set:
srand(time(nullptr))
also, I wouldn't recommend to use std::rand(), use the random header instead.
std::random_device rd;
std::mt19937 gen(rd());
auto x = gen();
0
I using srand(time(0));
0
0 is not null.
(void*)0 is null not nullptr.
0
does the same thing
it won't matter
0
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(0));
int x = rand();
}
0
ReimarPB it's don't work for me.
0
BuddyValera are you outputing the value ?
0
Yeah
0
Cain Eviatar here is my code:
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void Aries() {
srand(time(0));
int f = rand();
int c;
cin » c;
if (c == 1) {
for (int x = 1; x < 2; x++) {
cout « "\nYour lucky number is: " « 1 + (rand() % 10) « endl;
}
if (f == 4) {
cout « "Hi";
}
}
}
int main() {
Aries();
}
0
ReimarPB I also need to use it in if()
0
inside for loop
f=1+(rand()%10)
cout <<"\nYour lucky number is: "<< f << endl;
edit: you don't need the loop, remove the for loop
- 1
BuddyValera oh I didn't know you wanted to output it
Just add "cout >> x;" to the code I made above