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?

11th May 2018, 6:42 AM
BuddyValera
BuddyValera - avatar
20 Respostas
+ 1
i think this is what you wanted https://code.sololearn.com/c5L06rLs94SD/?ref=app
11th May 2018, 12:52 PM
‎ ‏‏‎Anonymous Guy
+ 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.
11th May 2018, 7:39 AM
Cain Eviatar
Cain Eviatar - avatar
+ 1
Sreejith yeah! It's what I needed. lol I dumb cus not tried this
11th May 2018, 1:07 PM
BuddyValera
BuddyValera - avatar
0
x = rand() is that what you wanted??
11th May 2018, 6:47 AM
‎ ‏‏‎Anonymous Guy
0
I tried do it. It's not working
11th May 2018, 6:52 AM
BuddyValera
BuddyValera - avatar
0
show your code
11th May 2018, 6:59 AM
‎ ‏‏‎Anonymous Guy
0
I can't do it rn. Maybe later ok?
11th May 2018, 7:00 AM
BuddyValera
BuddyValera - avatar
0
sure
11th May 2018, 7:01 AM
‎ ‏‏‎Anonymous Guy
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();
11th May 2018, 7:28 AM
Cain Eviatar
Cain Eviatar - avatar
0
I using srand(time(0));
11th May 2018, 7:32 AM
BuddyValera
BuddyValera - avatar
0
0 is not null. (void*)0 is null not nullptr.
11th May 2018, 7:33 AM
Cain Eviatar
Cain Eviatar - avatar
0
does the same thing it won't matter
11th May 2018, 7:36 AM
‎ ‏‏‎Anonymous Guy
0
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); int x = rand(); }
11th May 2018, 8:35 AM
ReimarPB
ReimarPB - avatar
0
ReimarPB it's don't work for me.
11th May 2018, 10:52 AM
BuddyValera
BuddyValera - avatar
0
BuddyValera are you outputing the value ?
11th May 2018, 11:00 AM
Cain Eviatar
Cain Eviatar - avatar
0
Yeah
11th May 2018, 11:01 AM
BuddyValera
BuddyValera - avatar
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(); }
11th May 2018, 11:24 AM
BuddyValera
BuddyValera - avatar
0
ReimarPB I also need to use it in if()
11th May 2018, 12:26 PM
BuddyValera
BuddyValera - avatar
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
11th May 2018, 12:43 PM
‎ ‏‏‎Anonymous Guy
- 1
BuddyValera oh I didn't know you wanted to output it Just add "cout >> x;" to the code I made above
11th May 2018, 12:25 PM
ReimarPB
ReimarPB - avatar