Rika_Z

list of your games

Aug 3rd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. using namespace std;
  6. int main()
  7. {
  8.     bool lever = true;
  9.     while (lever == true)
  10.     {
  11.         cout << "\t\t\tList of your likest games\n";
  12.         cout << "Enter 'enum' to enumeration\n";
  13.         cout << "Enter 'add' to add\n";
  14.         cout << "Enter 'delete' to delete\n";
  15.         cout << "Enter 'exit' to exit\n";
  16.         string entValue;
  17.         cin >> entValue;
  18.         vector<string> games;
  19.         vector<string>::iterator iterGames;
  20.         if (entValue == "enum")
  21.         {
  22.             if (games.empty())
  23.             {
  24.                 cout << "Your list is empty\n\n";//если массив пуст он должен вывести это
  25.             }
  26.             else
  27.             {
  28.                 cout << "Your games\n";
  29.                 for (iterGames = games.begin(); iterGames < games.end(); ++iterGames)//если нет то
  30.                 {                                                           //перебрать массив
  31.                     cout << *iterGames << endl;                             //но он всегда выводит что массив пуст
  32.                 }                                                           //хотя там есть данные
  33.                 cout << "\n\n";
  34.             }
  35.         }
  36.         else if (entValue == "exit")
  37.         {
  38.             cout << "You exit from list of games\n";
  39.             lever = false;
  40.         }
  41.         else if (entValue == "add")
  42.         {
  43.             string gameName;
  44.             do
  45.             {
  46.                 cout << "Enter name of game('back' to exit)\n";
  47.                 cin >> gameName;
  48.                 games.push_back(gameName);
  49.                 /*for (iterGames = games.begin(); iterGames != games.end(); iterGames++)
  50.                 {
  51.                     cout << *iterGames << endl;
  52.                 }*/
  53.             } while (gameName != "back");
  54.         }
  55.         else if (entValue == "delete")
  56.         {
  57.             string gameDelete;
  58.             cout << "Enter name of game you need to delete\n";
  59.             cin >> gameDelete;
  60.             iterGames = find(games.begin(), games.end(), gameDelete);
  61.             //iterGames == games.begin() + i;
  62.             for (int i = 0; i < games.size(); ++i)
  63.             {
  64.                 if (iterGames == games.begin() + i)
  65.                 {
  66.                     cout << "Game foung end delete\n\n";
  67.                     games.erase(games.begin() + i);
  68.                 }
  69.             }
  70.         }
  71.         else
  72.         {
  73.             cout << "Invalid key\n\n";
  74.         }
  75.  
  76.     }
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment