// ***************************************************************** // Author: Zhixiang Chen // Class: CSCI/CMPE 1170, Spring 2009 // Lab 10: Simple for-loops // Date: January, 2009 // Comment: The code here is meant to be revised. // //----------------------------------------------------------------- // // This lab exercise is to play with simple for-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 /************************************************************ Part A. A counter controled for-loop ************************************************************/ cout<<"************** PLay Counter Controled For-Loop************/"; cout<<" Enter How many integers do you want to play with? => "; cin>>counter; //start the loop for ( sum=min=max=avg =0; cunter > 0; counter-- ) //loop control: initialization, condition, update { cout<<"Enter an interger ==> "; cin>>number; sum += sum; if (number > max) max = number; if (number < min) min = number; } cout<<" You entered " << counter << " many integers. " < ", cin>>number; //loop initialization number != -99; //loop condition cout<<"Enter an interger ==> ", cin>>number) //loop update { counter += 1; sum += sum; if (number > max) max = number; if (number < min) min = number; } cout<<" You entered " << counter << " many integers. " < ", cin>>number; //loop initialization true; //loop foever but break out within cout<<"Enter an interger ==> ", cin>>number) //loop update { if (number == -99) { 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. " <