mardi 5 janvier 2021

How to get the occurence of a number?

I managed to get the highest number that the user enters for n times, but I couldn't seem to get its occurrence. Here is my code:

 # include <iostream>
 
 using namespace std;
 
 int main () {
    
    int n = 0, num = 0, i = 1, highest = 0, occurence = 0;
     
    cout << "Please the number of numbers that you will enter: ";
    cin >> n;

    while (i <= n) { 
        cout << "\n" << "Enter a number: ";
        cin >> num;
        i = i + 1;
    
        if (number > highestNumber) {
            highestNumber = number;
            occurence += 1;
        }
    }

Aucun commentaire:

Enregistrer un commentaire