+ 3

How to print random lines of your choice

Hello I just created the program which will take ABC and counting test now I just wanted to upgrade it a little how can we print random lines For example if your answer is correct The line is printed good and he next line is printed as follow keep going you are doing well Please explain it for me what ever solution it has as I am new to programming 😊😊😊😊Thanks in Advance😊😊😅 Link to my code https://code.sololearn.com/cTPYrA17YKw8/?ref=app

16th May 2019, 2:10 AM
Arslan Iftikhar
Arslan Iftikhar - avatar
3 Respuestas
+ 19
You can use array of string values(write sentences there as elements of that array), after that you can generate a random number from 0 to (length of array-1) & use it to take out a random sentence from array & print it. //for printing multiple lines, you can do something like generating random number for each line & see whether it is even or odd(using %2==0) to decide printing of that line.
16th May 2019, 4:15 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
you can make a function with local static array of strings or std::vector with all strings you want then return a random one every call at least I know you can make a use of the silly old rand(); oh and if you want it to be unique all you have to do is to replace the used string with anything and add an if statement just before the end of the function .....you can do it .
17th May 2019, 2:44 PM
‎وائل عبد الحق‎
‎وائل عبد الحق‎ - avatar
+ 2
Yeah thanks
16th May 2019, 7:53 AM
Arslan Iftikhar
Arslan Iftikhar - avatar