CJCoding With Joseph
15free / daySign inCreate account

Total the Prices

An array already holds a short list of prices: 4, 8, 15, 16, 23, and 42. Use a foreach loop to add every value together and print the grand total. A foreach loop is handy here because you only care about each value, not its position in the array, so you never have to manage an index yourself. Keep a total variable outside the loop and add each price to it.

Expected Output:

108

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Loops
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.