Let's look at lines 21 - 27:
1 2 3 4 5 6 7
|
if (var > 0)
{
bool first = false;
}
|
You're creating a new variable called
first
, which is not the same as referring to the other
first
created on line 16. This new variable has a more localized scope, and will cease to exist outside of that
if
branch. The same is true for lines 28 - 34 and 35 - 40 and the variables created in those branches.
Let's look at line 43:
if (first = true)
This is not doing what you think it's doing. Remember,
=
is assignment,
==
is the binary equality operator.
On line 31, you print an error message if the user enters zero. If you've decided that zero is an invalid input, then you need to make sure that this is also accounted for before / when you enter the while loop. If the first value you enter is a zero, your program will happily accept it.
You'll also need a way to store the values that were entered. An array or a vector maybe.