Good. Couple notes:
A compiler says:
In function 'int main()':
8:8: warning: unused variable 'avg' [-Wunused-variable] |
Some compilers are or can be told to be verbose. Verbose is good. Paying attention to messages is good.
This one is a "warning", the compiler asks: "
Are you sure about that?"
You declare a variable "avg", but never use it. Why is it there?
1 2
|
bool loop;
loop = false;
|
You declare a variable. Then you set its value. It is preferred to set a value (initialize) in the declaration:
bool loop = false;
[EDIT] was missing =
(We
know that you
know how, for you do it for summation and count.)
while (!loop)
means/(can be written too)
while (not loop)
The meaning of "loop when not loop" is unexpected. The names of the variables should make sense to a reader.
(float)summation
uses C syntax for cast. Casts should be rare and easy to spot.
The C++ cast syntax is more precise and noticeable:
static_cast<float>(summation)
The recommended floating point type now is
double
. The less precise float is for cases, where it is sufficient and/or space counts.
Integer value 0 converts to false. All other integer values convert to true.
Therefore,
if (count!=0)
and
if (count)
behave the same.
If I type "hello", the
cin >> mark;
will fail to get a number and put
cin
in failed state, where all future reads fail too. In other words, if input data is not plain integers, then the loop will run forever.
If you need to have a flag, then have it, but this would be safer:
1 2 3
|
int mark;
while ( cin >> mark && mark ) // Stop if read fails or mark==0
{
|