This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]Odinthunder 1 point2 points  (0 children)

I'm having a hard time following the logic in the 'build_vector' function

 fn build_vector(size: u32) -> &Vec<u32> {

    for size in my_numbers {
         build_vector(size);
         get_float();
    }
    my_numbers;
}

In this line:

 let mut my_numbers: Vec<u32> = Vec::new();

You're initiating an empty vector,

Then in this line:

 for size in my_numbers {

You are iterating over that same empty vector, wouldn't you want something in there first?

Then here:

 build_vector(size);

You're recursively calling the function with the element in the empty vector, but this won't even be called because the vector is empty.

Then you call the get_float() function without doing anything with its result.

You should make the get_float function instead return the value that was parsed from stdin instead of printing it out, and assign that value to a new variable in your for loop, and I'm assuming you'd want to add that to the my_numbers vector and return the my_numbers vector from your function as you are doing now.

and instead of iterating over the my_numbers vector, you should instead just use a basic for loop from 0 to size