fork(1) download
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <ctime>
  6. using namespace std;
  7.  
  8. string get_random_name(string arr[], int& nums)
  9. {
  10. int num = rand() % nums;
  11. string name = arr[num];
  12. arr[num] = arr[nums - 1];
  13. --nums;
  14. return name;
  15.  
  16.  
  17. }
  18.  
  19. int main()
  20. {
  21.  
  22. string num_names[6];
  23. int num_of_names = 0;
  24. int seed;
  25. int N = 6;
  26.  
  27. cout << "== Who Should I Text? ==" << endl;
  28. cout << "Enter seed" << endl;
  29. cin >> seed;
  30. srand(seed);
  31. while(std::cout << "Enter friend " << num_of_names << endl,
  32. std::cin >> num_names[num_of_names])
  33. {
  34. ++num_of_names;
  35. }
  36.  
  37.  
  38. cout << "You should text: " << get_random_name(num_names, num_of_names) << endl;
  39.  
  40. cout << "These other friends didn't make the cut:" << endl;
  41.  
  42. for (int i = 0; i < num_of_names; ++i)
  43. {
  44. cout << num_names[i] << endl;
  45. }
  46. return 0;
  47.  
  48. }
  49.  
Success #stdin #stdout 0s 3436KB
stdin
21
Adam
Bill
Cat
Damion
Edward
stdout
== Who Should I Text? ==
Enter seed
Enter friend 0
Enter friend 1
Enter friend 2
Enter friend 3
Enter friend 4
Enter friend 5
You should text: Bill
These other friends didn't make the cut:
Adam
Edward
Cat
Damion