Calculate sum using do...while loop - C++ Statement

C++ examples for Statement:do while

Description

Calculate sum using do...while loop

Demo Code

#include <iostream>
using namespace std;
int main()//w w w .j a  va  2s .c  o  m
{
   int  sum = 0;
   int  n = 0;
   do {
      cout << "Enter a number (0 for exit): ";
      cin >> n;
      n += sum;
   } while (n > 0);
   cout << "The sum is " << sum << endl;
   return 0;
}

Result


Related Tutorials