#include <iostream>
int main ()
{
int v1, sum = 0, end = 0;
while (end = 0)
{
std::cout << "Enter a negative or positive number (enter 0 to exit)" << std::endl;
std::cin >> v1;
if (v1 = 0)
{
++end;
}
else
{
if (v1 < 0) ++sum;
}
}
std::cout << sum << " of the numbers you entered were negative." << std::endl;
std::cin >> v1;
return 0;
}
This code seems straightforward enough but it doesn't work and I can't seem to figure out why.
It seems to me that I declare that the integrer end is "0" and in the very next statement I tell the program that as long as end is "0" the while loop whould continue.
But the program simply skips the while loop altogether, only initiating it if I cange its parameters to something else (like end <= 0).
If I do that, however, there seems to be no way of getting out of the loop.
Oh, thanks a bunch. I remember reading that a long while back on this page, but the book I'm using now hasn't covered that yet.
I thought I was losing my grip of reality there for a second. :)