- Version
- Download 14
- File Size 1.33 KB
- File Count 1
- Create Date April 18, 2016
- Last Updated April 18, 2016
Do While Loop in C++
Do While Loop in C++
This is program in c++ that demonstrate how do while loop functions in c++. The user will asked how many numbers he/she wants to enter, then program will compute the sum of the numbers entered by the user.
Source code:
#include < iostream >
using namespace std;
int main()
{
int numbersToCompute, x=0;
double sum=0, numValue;
cout << "enter number of numbers to compute" << endl;
cin>>numbersToCompute;
do
{
cout << "enter value: " << endl;
cin>>numValue;
sum=sum+numValue;
x++;
}while(x < numbersToCompute);
cout << "sum of "<< numbersToCompute <<" numbers = " << sum << endl;
return 0;
}