How do you end the loop, by pushing SPACE ?
I've tried using the value 32.... doesn't work.
Code:while ( value == 32 || value < 0 ) { std::cin >> value; if ( value < 0 ) { sum += 1; } }
regards,
The SharK
How do you end the loop, by pushing SPACE ?
I've tried using the value 32.... doesn't work.
Code:while ( value == 32 || value < 0 ) { std::cin >> value; if ( value < 0 ) { sum += 1; } }
regards,
The SharK
Studying programming languages,
you'll ALWAYS be a student ;-)
You cannot do it like that because operator >> ignores all whitespace. You can use get() to get a single character at a time if you are getting characters. If you are getting integers, how were you expecting the integers to be separated in the first place? Normally they are separated by whitespace.
If you are expecting each value to be separated by a newline, and then a space ends the loop, then there is no simple solution. I'd suggest using getline to read in a string, then converting each string to an int with a stringstream. Before doing that check for an empty string which means the user typed enter without inputting a number. You should also check the result of the stringstream conversion to make sure the value entered really was a number.
This ends when you enter a non-space character, you got it reversed...Code:while ( value == 32 || value < 0 )
And as Daved said, you can't get it working like this.
Last edited by maxorator; 11-25-2006 at 01:50 AM.
"The Internet treats censorship as damage and routes around it." - John Gilmore
yeah, maxorator
ya, know when you program late at night....
actually I end up writing this instead of using SPACE:
Code:while ( value != 0 ) { std::cin >> value; if ( value < 0 ) sum += 1; }
Studying programming languages,
you'll ALWAYS be a student ;-)