Is it possible for both the "rand() and srand()" functions to output string and any other datatype apart from int?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Is it possible for both the "rand() and srand()" functions to output string and any other datatype apart from int??

I made an array of codes in string so i could mix the strings around. I'm not sure how to write the code for this description, I wanted to know first if it was possible. But here's my code https://code.sololearn.com/cA12a19a237A/?ref=app

24th Jan 2021, 6:36 PM
Shapa
Shapa - avatar
3 Answers
+ 3
You could generate random numbers and use them as index for accessing the string array. https://code.sololearn.com/c8CvADr7h3wA/?ref=app
24th Jan 2021, 9:35 PM
JaScript
JaScript - avatar
+ 2
ataladin 87 I have updated the above mentioned code. Now you can write something whenever only a city comes up. And if a specific city is randomly selected you will get an additional information about it. Furthermore happy coding.
25th Jan 2021, 6:22 PM
JaScript
JaScript - avatar
+ 1
ataladin 87 in addition You could for example code a second array with the information about each city, where the items have the same indexes as citys in them array.
25th Jan 2021, 8:16 AM
JaScript
JaScript - avatar