m1m8

Untitled

Oct 2nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. const int MAX_PLAYERS = 2;
  8.  
  9. int choice = 0;
  10.  
  11. // pointing to array on the heap
  12. string* playerList = new string[MAX_PLAYERS];
  13.  
  14. // enter player names in playerList
  15. for (int i = 0; i < MAX_PLAYERS; i++)
  16. {
  17. cout << "Enter player's name..." << endl;
  18. getline(cin, playerList[i]);
  19. system("cls");
  20. }
  21.  
  22. // display list of players
  23. for (int i = 0; i < MAX_PLAYERS; i++)
  24. {
  25. cout << playerList[i] << endl;
  26. }
  27.  
  28. // Main Menu
  29. while (playerList)
  30. {
  31. cout << "Do you want to drop player from list?" << endl;
  32. cout << "1.Yes" << endl;
  33. cout << "2. No" << endl;
  34. cin >> choice;
  35. system("cls");
  36.  
  37. if (choice == 1)
  38. {
  39. cout << "Which name would you like to delete?" << endl;
  40. cout << "1. " << playerList[0] << endl;
  41. cout << "2. " << playerList[1] << endl;
  42. cin >> choice;
  43.  
  44.  
  45. if (choice == 1)
  46. {
  47. delete[0] playerList;
  48. }
  49.  
  50. // check if slots are empty
  51. for (int i = 0; i < MAX_PLAYERS; i++)
  52. {
  53. if(!playerList[0])
  54. cout << "empty slot" << endl;
  55. }
  56.  
  57. }
  58. if (choice == 2)
  59. {
  60. cout << "goodbye" << endl;
  61. playerList = nullptr;
  62.  
  63. }
  64. if ((choice != 1) || (choice != 2))
  65. {
  66.  
  67. }
  68. }
  69.  
  70.  
  71. delete[] playerList;
  72.  
  73. system("pause");
  74. return 0;
  75.  
  76.  
  77. }
Add Comment
Please, Sign In to add comment