+ 2

How do i make my code choose a random varible/number/letter?

Im pretty sure that its possible, but im new and i dont know how. If my question isnt specific enough, i mean like, for example to be used together with the 'switch' statement, with a outcome out of a few possible, if that makes sense... Sorry, im bad at explaining. All help is apreciated, thank you.

29th Apr 2017, 11:02 AM
marty
marty - avatar
3 odpowiedzi
+ 24
You mean something like this?.. For switch case you can store the output of the random no generator into some variable(b in code) and then switch that variable like switch(b) and carry out desired cases https://code.sololearn.com/cNYIFy3OFNM5/?ref=app
29th Apr 2017, 11:03 AM
Frost
Frost - avatar
+ 6
do you know how to get true random numbers yet? that will help in the process. :) pretty sure the course here discusses the topic of random number generation. next would be having your program react to the random number. for first attempts i would use if statements to check if the number is within a certain range : if(randomnumber >= startRange && randomNumber <= endRange) { cout << "solo learn is awesome:; }
29th Apr 2017, 11:09 AM
jay
jay - avatar
+ 2
Thank you!
29th Apr 2017, 11:10 AM
marty
marty - avatar