Whileloop controlled by a sentinel value Write a program tha
(While-loop controlled by a sentinel value) Write a program that reads an unspecified number of integers. Your program ends with the input 0. Determine and display how many positive and negative values have been read, the maximum and minimum values, and the total and average of the input values (not counting the final 0).
Solution
Here we will take one counter ncount which will hold the value for entered negative numbers and pcount to hold the count of eneterd postive number, average will hold the average of numbers, sum and tcount are variable are intermediate varibale to calculate average.
#include<iostream.h>
#include<conio.h>
void main()
{int ncount = 0, pcount=0 , sum=0;
int num,tcount;
int max = 1,min=0;
float average;
do
{
cout<<\"Enter the number\"<<endl;
cin>>num;
if(num<0)
{ncount++;
}
else if(num>0)
{pcount++;}
if(num>max)
max= num;
if(num<min)
min= num;
sum= sum+num;
}while(num!=0);
tcount = ncount+pcount;
average = sum/tcount;
cout<<\"The average of input number is\"<<average<<endl;
cout<<\"Maximum number is\"<<max<<endl;
cout<<\"Minimum number is\"<<min<<endl;
}
