C++ Online Compiler
Example: Accumulator Variable for Summation in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Accumulator Variable for Summation #include <iostream> using namespace std; int main() { // Step 1: Declare and initialize integer variables int valueA = 5; int valueB = 12; int valueC = 8; // Step 2: Initialize an accumulator variable for the sum int totalSum = 0; // Step 3: Add each value to the totalSum totalSum = totalSum + valueA; // totalSum is now 5 totalSum = totalSum + valueB; // totalSum is now 5 + 12 = 17 totalSum = totalSum + valueC; // totalSum is now 17 + 8 = 25 // Step 4: Display the final result cout << "The total sum using an accumulator is: " << totalSum << endl; return 0; }
Output
Clear
ADVERTISEMENTS