Answer:
Following are the fragment of code which is written in C++ Programming Language:
float number1=-1; // variable declaration float type
float count1=0; // // variable declaration float type
float sum1=0; // // variable declaration
while(cin.eof( )==false) // iterating the loop
{
cin >> number1; // read the number by user
sum1 += number1; // performing sum operation
count1++; // increment of count by 1
}
if(number1==-1) // checking condition
{
cout << "no values to average";
}
else
{
if (count1 > 0 )
cout << sum1/count1;
}
Step-by-step explanation:
Here, set three float data type variable "number" to 1, "count" to 0 and "sum" to 0. Then, we set the while loop, pass the condition "cin.eof( )==false". Then, we set the if statement, pass the condition "number==-1" and then, we set the else statement, inside it pass if statement.