// ***************************************************************** // Author: Zhixiang Chen // Class: CSCI/CMPE 1170, Spring 2009 // Lab 11: Simple do-while loops // Date: January 12, 2009 // Comment: The code here is meant to be revised. // //----------------------------------------------------------------- // // This lab exercise is to play with simple do-while loops to process // a list of integers and find simple statistical information // // Compile and run your program. When everything is fine, // print your .cpp file and turn it to me or the TA. // ***************************************************************** #include < iostream > #include #include < string > #include < cstring > #include < cmath> #include #include using namespace std; int main( ) { //variable declarations int number; //var to store an int value int sum, min, max, avg; //vars to store simple statistical info int counter; //a counter for controling the loop int size; //another counter /************************************************************ Part A. A counter controled do-while loop ************************************************************/ cout<<"************** PLay Counter Controled do-while-Loop************/"; //initialization sum=min=max=avg =0; cout<<" Enter How many integers do you want to play with? => "; cin>>counter; //get the counter size = counter; //memory the counter //The control condition is at the end. This means that we enter the loop first //regardless the condition do { cout<<"Enter an interger ==> "; cin>>number; //get a number sum += sum; if (number > max) max = number; if (number < min) min = number; }while (counter-- > 1); cout<<" You entered " << counter << " many integers. " < "; cin>>number; //get a number if (number != -99) //check for event but cannot break in for practice { counter++; //count numbers sum += sum; if (number > max) max = number; if (number < min) min = number; } }while ( number != -99); //use event -99 to control the loop cout<<" You entered " << counter << " many integers. " < "; cin>>number; if (number == -99) //check for event -99. If happened, then break { cout<<" Event -99 happened, so break out......... "; break; } counter += 1; sum += sum; if (number > max) max = number; if (number < min) min = number; } cout<<" You entered " << counter << " many integers. " <