Recap - Dynamic Input
Part of the Fundamentals section of Coddy's C++ journey — lesson 50 of 74.
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:
12Explanation:
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
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison3Variables Part 2
Type DeclarationNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementConditional OperatorRecap - If ElseNested If - Else9Loops
For Loop Part 1While LoopDo While LoopBreakContinueFor Loop Part 2Nested LoopsInfinite LoopsRecap - Dynamic Input