#[C++] Exercise "making-the-grade"

2 messages · Page 1 of 1 (latest)

pallid ridge
#

https://exercism.org/tracks/cpp/exercises/making-the-grade/

Hey there.
I'm a bit stuck at the 1. task of this exercise called "making-the-grade" where I need to perform a type cast for each member of an given array.

Even though the hints suggest to use a while loop and some vector methods to solve this, I kind of don't get the hang of it.

What I tried

// Round down all provided student scores.
std::vector<int> round_down_scores(std::vector<double> student_scores) {
    // TODO: Implement round_down_scores
    int i = 0;
    while(i < student_scores.size()){
        student_scores[i] = static_cast<int>(student_scores[i]);
        i++;
    }
    return student_scores;
}

I'm familiar with looping over things but for some reason I get conversion error as seen in the screenshot.

I would appreciate any additional hints or ways to think about it so I can solve it.

wispy yoke
#

The problem is that std::vector<double> and std::vector<int> are two separate types, they cannot be implicitly converted to each other.
That's what the compiler is telling you:

error: could not convert 'student_scores' from 'vector<double>' to 'vector<int>'

You will have to create a new std::vector<int> in some way.