Menu
Coddy logo textTech

Recap - Dynamic Input

Part of the Fundamentals section of Coddy's C++ journey — lesson 50 of 74.

challenge icon

Challenge

Write a program that first accepts an integer n, representing how many additional whole numbers will be entered next. Then, read exactly n whole numbers from the input. Finally, compute and print the sum of those n numbers (excluding the first input).

Input:
3
1
5
6

Output:
12

Explanation:

The first number 3 means that the next 3 numbers (1, 5, and 6) will be read and summed. The total is 1 + 5 + 6 = 12

If you are stuck, read the hints!

Try it yourself

#include <iostream>

int main() {
    int numLoops;
    std::cin >> numLoops;
    int sum = 0;
    // Write your code below
    // Iterate numLoops times
    // In each iteration get the input using std::cin >> num;

    return 0;
}

All lessons in Fundamentals