total beginner with while

Hey, how should i count the average of numbers that were inputed until 0. All the nubers should make their output and then the average. I dont know what to divide the sum with. I know i shoul make one more variable. Thanks!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main (){
float a=1,avg=0,sum=0;//a-the number, avg-average
while(a>0){

 cin>>a;
 sum=a+sum;
}

avg=sum/   ;//???

return 0;
}
Last edited on
Make a variable called "number_of_values_entered".

This variable should start with the value zero.

This variable should be increased by one every time a value is entered.
Topic archived. No new replies allowed.