+ 1

How to use the output result for a different operation

I made a simple code truly random numbers. How do I use the result for another if statement? https://code.sololearn.com/c0Us16zB0tL5/?ref=app

19th Feb 2018, 10:16 PM
Victor Takev
Victor Takev - avatar
4 odpowiedzi
0
I don't know if I am properly understanding your problem... But you could save that randomly generated number in a variable like this: int myRandom = 1 +(rand () % 5); So you would be able to use that random number later.
19th Feb 2018, 10:53 PM
Néstor Misut Camacho
Néstor Misut Camacho - avatar
0
I used your solution, but the "if" statement is comparing only the first number from top to bottom. Is it recognizing all the numbers? And if it is how do I use the second and third number in the evaluation.
19th Feb 2018, 11:16 PM
Victor Takev
Victor Takev - avatar
0
I think what you are trying to do is the following: for (int x = 1; x <= 3; x++){ int myRandom = (rand () % 5); cout << 1 + myRandom << endl; if (myRandom > 3){ cout << "I rule\n"; } if (myRandom < 3){ cout <<"you rule\n"; } } give it a try
20th Feb 2018, 12:20 AM
Néstor Misut Camacho
Néstor Misut Camacho - avatar
0
Ok thanks for the help, now I am comparing the positions in the array, but it's confusing the coat lines of text. That are associated with the numbers.😁
20th Feb 2018, 1:42 AM
Victor Takev
Victor Takev - avatar