0

My intention is after pushing pair to vector temp_pairs, compare it's 2 elements with the elements of the vector of vectors jumpers, and if one element of temp_pairs is equal to any element of jumpers .clear() the temp_pairs. The following code works, except for the 2 first pairs.

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;

typedef std::vector<int> vector_i;
typedef std::vector<char> vector_c;

vector_c control {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','w','y','z',' ','.'};

std::vector<vector_c> jump_input();

int main()
{
    jump_input();
    return 0;
}

std::vector<vector_c> jump_input()
{
    std::vector<vector_c> jumpers;
    vector_c temp_pairs(2);
    int jump_count = 0;
    char in;
    vector_c pair;
    
    do
    {
        for (int i = 0; i < jumpers.size(); i++)
        {
            for (int j = 0; j < jumpers[i].size(); j++)
            {
                std::cout << jumpers[i][j];
            }
            std::cout << " ";
        }

        for (int i = 0; i < 2; i++)
        {
            std::cout << "\n" << "Enter the " << i+1 << " of the pair number "<< jumpers.size()+1 << "\n";
            std::cin >> in;

            for (int j = 0; j < control.size(); j++)
            {
                if (in == control[j])
                {
                    pair.push_back(in);
                }
            }  
        }

        if (pair.size()>1)
        {
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < control.size(); j++)
                {
                    if (pair[i] == control[j])
                    {
                        temp_pairs.push_back(pair[i]);
                    }
                }
            }          
        }

        // where the comparation happens
        for (int i = 0; i < jumpers.size(); i++)
        {
            for (int j = 0; j < 2; j++)
            {
                if (jumpers[i][j] == temp_pairs[j])
                {
                    temp_pairs.clear();
                }
            }
        }

        if (!temp_pairs.empty())
        {
            jumpers.push_back(temp_pairs);
            jump_count += 1;
        }

        temp_pairs.clear();
        pair.clear();
        in='\0';

    } while (jump_count<21);
    
    return jumpers;
}

Terminal image enter image description here

I tried series of if statements and for loops, and this is the best result i code reach.

  • You'll be glad to hear you don't need anyone's help to figure this out, just a tool you already have: your debugger! This is exactly what a debugger is for. It [runs your program, one line at a time, and shows you what's happening](https://stackoverflow.com/questions/25385173/), this is something that's every C++ developer must know how to do. With your debugger's help you'll able to quickly find all problems in this and all future programs you write, without having to ask anyone for help. Have you tried using your debugger, already? If not, why not? What did your debugger show you? – Sam Varshavchik Nov 16 '22 at 22:56
  • I can se that the first roll is pushing 4 elements to jumpers[0]. Thank you! – Walber José Neves Nov 16 '22 at 23:12

0 Answers0