fork 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. srand(time(NULL));
  22. string num_names[6];
  23. int num_of_names;
  24. int N = 6;
  25.  
  26. cout << "== Who Should I Text? ==" << endl;
  27. cout << "Enter seed" << endl;
  28. cin >> num_of_names;
  29.  
  30. for (int counter = 0; counter < num_of_names; counter++)
  31. {
  32. cout << "Enter friend " << counter << endl;
  33. cin >> num_names[counter];
  34. }
  35.  
  36.  
  37. cout << "You should text: " << get_random_name(num_names, num_of_names) << endl;
  38.  
  39. cout << "These other friends didn't make the cut:" << endl;
  40.  
  41. for (int i = 0; i < num_of_names; ++i)
  42. {
  43. cout << num_names[i] << endl;
  44. }
  45. return 0;
  46.  
  47. }
Success #stdin #stdout 0s 3480KB
stdin
4
Sam
Max
Sarah
Rose
stdout
== Who Should I Text? ==
Enter seed
Enter friend 0
Enter friend 1
Enter friend 2
Enter friend 3
You should text: Sam
These other friends didn't make the cut:
Rose
Max
Sarah