How to identify common values in an array and print it without repeating any repeated values?

  arrays, c++, for-loop, loops

It has been quite challenging for me to do this. There are 2 arrays, and their elements are from the user’s input. At the end of the input process, the program must identify the similar numbers from both arrays.

Here is my code:

 # include <iostream>
 using namespace std;
 
 int main () {
    
    int i, j, k;
    float list_A [5];
    float list_B [5];
    
    
    cout << "nHello! This program lets you input 2 lists of numbers, List A and List B, with five numbers per list. nn";
    
    cout << "For List A, please enter some numbers below.n";
        
        for (i = 0; i < 5; i = i + 1) {
            cout << "tEnter a number: ";
            cin >> list_A [i];
        }
    
    cout << "For List B, please enter some numbers below. n";
    
        for (j = 0; j < 5; j = j + 1) {
            cout << "tEnter a number: ";
            cin >> list_B [j];
        }
        
    cout << "nnANALYSIS";
    cout << "n------ ----- ----- ----- ------n";
    
    cout << "Numbers entered in List A: ";

        for (i = 0; i < 5; i = i + 1) {
            cout << list_A [i] << "  ";
        }
        cout << "n";
    
    cout << "Numbers entered in List B: ";
    
        for (j = 0; j < 5; j = j + 1) {
            cout << list_B [j] << "  ";
        }
        cout << "n";
    
    cout << "Common numbers between the two lists: ";
        
        for (i = 0; i < 5; i = i + 1) {         // identifying starts here
            for (j = 0; j < 5; i = i + 1) {
                if (list_A [j] == list_B [j]) {
                    cout << list_A [j] << "  ";
                }
            }
        }

Thanks in advance!

Source: Windows Questions C++

LEAVE A COMMENT