Sunteți pe pagina 1din 2

#include<cstdio> #include<csdlib> #include<iostream> using namespace std; int main(int nNumberofArgs,char*pszArgs[]) { //input the loop count int a ccumulator=0;

cout<<"This program sums values entered" <<"by the user\n"; cout<<"Terminate the loop by entering" <<"a negative number\n"; //loop"forever" for(;;) { //fetch another number int value=0; cout<<"Enter next number:"; cin >>value; //if it's negative... if(value<0) { //...then exit break; } //...otherwise add the number to the

//accumulator accumulator=accumulator+value; } //now that we've exited the loop //output the accumulator result cout<<"\nThe total is" <<accumulator <<"\n";

S-ar putea să vă placă și