Kodewick
Start learning →
Starter←→0 / 86

Add Up to n

#077Startertotal += i3 min

Work out the total of 1 up to n. The loop and the output are already written — only the line inside the loop is missing. n is 10, so the answer is 55.

Should show
55
main.cpp
#include <iostream>
using namespace std;

int main() {
    int n = 10;
    int total = 0;
    for (int i = 1; i <= n; i++) {
        // your code here: add this round's i into total
    }
    cout << total << endl;
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.