Okay, I'm trying to do a lot of my labs for my C++ class because I'm a little behind so please try to answer.. I can ask tomorrow in class but just wanting to know what this means so I can get it done tonight. My professor gave us half of a program with these examples:
Part A. A counter controled while loop
Part B. Sentinel/Event controled while loop loop
Part C. Sentinel/Event controled loop -break out within the loop
basically gave us a model of each..which I get all these loops, but then there is the part he wants us to do which matches his set:
Part A. Write a counter-controled while-loop to process only event numbers
Part B. Write an event-controled while-loop to process only event numbers
Part C. Write an event-controled while-loop to process only event number This breaks within the loop
I don't understand the "process only event numbers". What numbers are these? I'm sorry if this is a dumb question, I actually thought he meant even numbers at first but I don't think so.. Can anyone please help me?
Sorry.. I should have posted that first but I don't think it has much on it.. It took me like an hour to fix all the problems his part had.. I hope he did that on purpose.. I couldn't even run it when I tried to test it.. :/ I really want to know what he means about event numbers because this program and the next two are the same, except he changes the types of loops to for, and do-while..
#include < iostream >
#include <fstream >
#include < string >
#include < cstring >
#include < cmath>
#include <cstdlib>
#include <iomanip>
usingnamespace 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 while loop
************************************************************/
cout<<"************** Play Counter Controled do-while-Loop************";
//initialization
sum=min=max=avg =0;
cout<<"\n\n Enter How many integers do you want to play with? => ";
cin>>counter; //get the counter
size = counter; //memory the counter
counter=0;
//start the loop
while (counter!=size)
{
cout<<" Enter an integer ==> ";
cin>>number; //get a number
sum += number;
if (counter==0)
max=min=number;
if (number > max)
max = number;
if (number < min)
min = number;
counter++;
}
cout<<" You entered " << counter << " integers. " <<endl
<<" The sum is " << sum <<endl
<<" The max is " << max <<endl
<<" The min is " <<min<<endl
<<" The Avg is " << sum / size<<endl;
/************************************************************
Part B. Sentinel/Event controled while loop loop
************************************************************/
cout<<"\n************** PLay Sentinel/Event controled while Loop************";
cout<<"\n\n Compute simple stats of integers. Stop -99 is entered.";
//intitialization
counter=sum=min=max=avg =0;
cout<<"\n Enter an integer ==> ";
cin>>number;
//start the loop
while (number != -99)
{
if (counter==0)
max=min=number;
counter++; //count numbers
sum += number;
if (number > max)
max = number;
if (number < min)
min = number;
cout<<" Enter an integer ==> ";
cin>>number;
}
cout<<" You entered " << counter << " integers. " <<endl
<<" The sum is " << sum <<endl
<<" The max is " << max <<endl
<<" The min is " <<min<<endl
<<" The Avg is " << sum / counter <<endl;
/************************************************************
Part C. Sentinel/Event controled loop -
break out within the loop
************************************************************/
cout<<"\n************** Play Sentinel/Event controled while-loop************\n"
<<"************** Break out within the loop **************************\n\n";
cout<<" Compute simple stats of integers. Stop -99 is entered.";
//initialization
counter=sum=min=max=avg =0;
//start the loop
while (true) //loop forever but break from within
{
//get a number
cout<<" Enter an integer ==> ";
cin>>number;
if (number == -99) //check for event -99. If happened, then break
{
cout<<" Event -99 happened, so break out......... "<<endl;
break;
}
counter += 1;
sum += number;
if (counter==1)
max=min=number;
if (number > max)
max = number;
if (number < min)
min = number;
}
cout<<" You entered " << counter << " integers. " <<endl
<<" The sum is " << sum <<endl
<<" The max is " << max <<endl
<<" The min is " << min<<endl
<<" The Avg is " << sum/counter<<endl;
/*********************************************************************************
The following three parts are for you to complete.
*********************************************************************************/
/*********************************************************************************
Part A. Write a counter-controled while-loop to process only event numbers
*********************************************************************************/
//your codes are here:
/*********************************************************************************
Part B. Write an event-controled while-loop to process only event numbers
*********************************************************************************/
//your codes are here:
/*********************************************************************************
Part C. Write an event-controled while-loop to process only event numbers
This breaks within the loop
*********************************************************************************/
//your codes are here:
//well done and exit
return 0;
}
I figured it out.. It was "process only even" numbers.. It took about an hour to correct all the mistakes his part originally had so I'm not surprised he typed in event instead of even in all 3 projects, 3 times in each one!! Sorry about that.... :)