Start learning free

LESSON 176 OF 679 · LOOPS & GLOBAL VARIABLES

Array Sum: Buggy Code in Rust

Practice

Inside the code editor we've tried to write a function that takes a vector nums as argument and prints to the console the sum of all numbers in that vector.

So when we called printSum(vec![1, 2, 3]), we expected our code to print:

6

because 1 + 2 + 3 = 6. But it seems like we made some mistakes because when we run our code, it prints:

1
2
3

Assignment:

Your task is to fix our function such that it correctly computes and prints the desired sum.

STEP 1 OF 1
    Ctrl + Enter to check