Hi, I just recently started looking into C++ programming so I don't know much.
I was wondering is it possible to write a program to pick a random name from a list of names, which are in a .txt file? or if I could ask the user to input the list of names and then let the program pick a random name?
I have it so that the maximum number of name entries is 100. The program will keep asking if you want a random name, the same random name can appear twice in a row. Hope it helps. PS. There are many other ways to implement using text files or whatever. Below, I use an string array.
you should use rand() once before you call it in your function because the first call to it is flawed... your function would produce better results... and you should call srand() too before you call rand() and include "time.h"... I think it's
1 2 3
srand( static_cast<unsignedint>(time(NULL)));
// then rand();
rand();
and then your code... enjoy!
[edit] Damn I didn't notice you had already called srand()... :-)
@JLBorges: Hi, I tried running the program but doesn't compile. Could you please include an example for how I have to enter the path of the file? Thanks.