Hello,
I need some help on processing only even numbers on a counter-controlled do-while-loop, an event-controlled do-while-loop, and event-controlled do-while-loop to process only even numbers that breaks within the loop.
I'm new at C++ so help would be appreciated.
Thanks.
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <limits.h>
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 D. Write a counter-controled do-while-loop to process only even numbers
*********************************************************************************/
//Write your code here:
cout<<"************** PLay Counter Controled do-while-Loop************\n";
//initialization
sum=max=avg =0;
min=INT_MAX; //min has the maximum integer valued assigned//changed by sirisha
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 += number;
if (number != 2%)
cout<<"Enter an interger ==> ";
cin>>number; //get a number
else
{
if (number > max)
max = number;
if (number < min)
min = number;
}
}while (counter-- > 1) ;
cout<<" You entered "<< counter << " many integers. " <<endl
<<" The sum is " << sum <<endl
<<" The max is " << max <<endl
<<" The min is " << min <<endl
<<" The Avg is " << sum / size<<endl;
/*********************************************************************************
Part E. Write an event-controled do-while-loop to process only even numbers
*********************************************************************************/
//Write your code here:
cout<<"************** PLay Sentinel/Event controled do-while Loop************\n";
cout<<" Compute simple stats of integers. Stop -99 is entered."<<endl;
//intitialization
counter=sum=max=avg =0;
min=INT_MAX;
//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
if (number != 2%) //check for event but cannot break in for practice
{
counter++; //count numbers
sum += number;
if (number > max)
max = number;
if (number < min)
min = number;
}
}while ( number != 2%); //use event -99 to control the loop
cout<<" You entered "<< counter << " many integers. " <<endl
<<" The sum is " << sum <<endl
<<" The max is " << max <<endl
<<" The min is " << min <<endl
<<" The Avg is " << sum/counter <<endl;
/*********************************************************************************
Part F. Write an event-controled do-while-loop to process only even numbers
that breaks within the loop
*********************************************************************************/
//Write your code here:
//well done and exit
return 0;
}
Here are the errors I get.
1>cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release
1>Lab11.cpp
1>g:\projects\lab11\lab11.cpp(154) : error C2059: syntax error : ')'
1>g:\projects\lab11\lab11.cpp(157) : error C2181: illegal else without matching if
1>g:\projects\lab11\lab11.cpp(187) : error C2059: syntax error : ')'
1>g:\projects\lab11\lab11.cpp(188) : error C2143: syntax error : missing ';' before '{'
1>g:\projects\lab11\lab11.cpp(196) : error C2059: syntax error : ')'