dimanche 27 août 2017

Rounding numbers to multiple of 5 C++

#include <iostream>
#include <vector>
int main(){
    std::ios::sync_with_stdio(false);
    int n;
    std::cin>>n;
    std::vector<int> grades(n);
    int fives[20];
    for(int i=0;i<20;i++)
        fives[i]=5*(i+1);
    for(int i=0;i<n;i++)
        std::cin>>grades[n];
    for(int i=0;i<n;i++){
        for(int j=0;j<20;j++){
            if(grades[i]==fives[j]-2||grades[i]==fives[j]-1||grades[i]==fives[j])
                grades[i]=fives[j];
        }
    }
    for(int i=0;i<n;i++)
        std::cout<<grades[i]<<" ";
}

I'm trying to round up numbers which is close to 2 or less point to multiple of 5. But output is just 0. Whats wrong with my code ?

Aucun commentaire:

Enregistrer un commentaire