0
You guys all right? I’m beginner and I’m trying to build a program that compares two vectors and if all the elements of the two vectors are. I’ll exemplify it to get better...
vector 1 = 10, 20 , 30 and vector 2 = 10 20 30; then the output will be: equal numbers.
vector 1 = 10, 20, 20 and vector 2 = 10, 20, 15; then the output would be: 10 20 and tbm saying these were the equal numbers.
vector = 10, 20, 30 and vector 2 = 15, 19, 4; so the output would be: no equal number. the problem is that when all numbers are equal, apart from him give out saying that all are equal he tbm ta showing the numbers and it is not for that happen.
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int vetorX[n], i, a,c[n];
for(a=0; a<n; a++){
cin >> vetorX[a];
}
int vetorC[10] = {19, 7, 14, 0, 11, 17};
int cont =0, cont1 = 0, cont2 =0;
for(i=0; i<n; i++){
for(a=0; a<n; a++){
//conta a quantidade de numeros iguais
if(vetorX[a] == vetorC[i]){
cont ++;
c[n] = vetorX[a];
cout << c[n];
}
}
}
if(cont >= 7){
cout << "todos iguais";
}
if(cont > 1 && cont < n){
cout << "numeros iguais:";
}
if(cont == 0){
cout << "nenhum igual";
}
}
It seems to me that if you count == 0 then you have none equal and if you count < 7 then there are some equal but not all. A situation that should be analyzed is what the result will be obtained if there is a repetition of some element in the vector(s) and what to do in this case.
– anonimo
I took his tip from scratch and it worked and the rest tbm, but if all the elements are equal it returns that are equal and displays the numbers tbm and I don’t want that to happen, I want that if all the numbers are equal it returns that, all are equal, without showing the numbers.
– Ayo
I don’t see the point in using 3 commands
if
with exactly the same condition.– anonimo
Yeah, I didn’t even realize it, so I took it. The problem is that it keeps displaying the numbers even if all the numbers are the same and it is not to roll this, it would be the case to put a condition for it to only display the numbers if there is any difference?
– Ayo