-1
I need to create a vector that in case see what the repeated numbers and give as output it, but if there are 2 values that have the same amount of repetition the output has to be the highest value
my code is like this for now
Dit: I’m not sure how to make the output give the highest value
ex:
entree:
6
5 5 5 3 3
output : 3
that’s what’s going on in my code and I’d need you to leave 5 but I don’t know how to do it
#include <iostream>
using namespace std;
int main() {
int n,i,nota ;
cin >> n;
int a[n];
for (int i = 0; i< n; i++){
cin >> a[i];
}
for(i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
if(a[i] == a[j]){
nota = a[j];
}
}
} cout << nota;
return 0;
}
Welcome @Davidfranca9, it would be interesting for you to tell us what your difficulties are and what is going wrong in your code so we can better help you. Your question is too vague.
– Guto
Your if shouldn’t be > instead of ==????
– Rebeca Nonato
but I’ve tried the same thing
– Davidfranca9
From what I understand your variable
nota
contains the last number that has been repeated, regardless of the number of repetitions or their value. The number of repetitions matters?– anonimo
Also not understood when it speaks of "2 vectors", its program treats a single vector.
– anonimo
and were 2 values not vectors I will correct
– Davidfranca9
Do you have to leave the bigger one, or what else happened? I didn’t understand
– Rebeca Nonato
has to give the exit of the most repeated, but if 2 values repeat also has to give the exit of the highest value
– Davidfranca9