C/C++ Arena

Step 3 of 6

Accumulating a total

A very common loop pattern: start a variable at 0 and add to it every round.

int sum = 0;
for (int i = 1; i <= 100; i++) {
    sum += i;
}

Your turn: the first number of input is n, followed by n damage values. Print the total damage and the highest single hit:

Input:

4
27 100 64 9

Output:

total 200
max 100

Previous: for loops Next: break and continue