Challenge: Running Total with a Lambda
Завдання
Swipe to start coding
Update the addToTotal function so that the returned lambda returns the current total after adding the input value.
- Implement the
addToTotalfunction to return a lambda that capturestotalby reference. - The lambda should take an integer argument, add it to
total, and return the updatedtotalvalue.
In your main function:
- Declare an integer variable named
totaland initialize it to zero. - Call
addToTotal, passingtotalas an argument, and assign its return value to a variable namedadder. - Call
adderthree times with the values 5, 10, and 15, each time printing the return value. - After the three calls, print the value of
totalto standard output.
Рішення
solution.cpp
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 3
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Suggested prompts:
Can you explain this in simpler terms?
What are the main points I should remember?
Can you give me an example?
Awesome!
Completion rate improved to 12.5
Challenge: Running Total with a Lambda
Свайпніть щоб показати меню
Завдання
Swipe to start coding
Update the addToTotal function so that the returned lambda returns the current total after adding the input value.
- Implement the
addToTotalfunction to return a lambda that capturestotalby reference. - The lambda should take an integer argument, add it to
total, and return the updatedtotalvalue.
In your main function:
- Declare an integer variable named
totaland initialize it to zero. - Call
addToTotal, passingtotalas an argument, and assign its return value to a variable namedadder. - Call
adderthree times with the values 5, 10, and 15, each time printing the return value. - After the three calls, print the value of
totalto standard output.
Рішення
solution.cpp
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 3
single