>> twomers. your code show the cout message in the while two times if I input one string.
Get rid of one then. I don't understand the language, so I didn't know what it said. So I didn't know if it was valid in the loop.
>> twomers. your code show the cout message in the while two times if I input one string.
Get rid of one then. I don't understand the language, so I didn't know what it said. So I didn't know if it was valid in the loop.
In twomers code, if the input has 1 char, it gives one error message, if the input has 2 chars it gives two error messages, and there you go...
Code:cout << "Input a number please.\n"; while ( !(cin >> MAX) ) { cout << "Error! Input numbers please! (0123456789)\n"; cin.clear(); cin.ignore(); cout << "Input a number please.\n"; }
twomers' code looks fine. I suggest that you post the smallest and simplest compilable program that demonstrates what you want to do.twomers. your code show the cout message in the while two times if I input one string.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Twomers code still uses that bad IF statement.Originally Posted by laserlight
"The Internet treats censorship as damage and routes around it." - John Gilmore
Wow, fastest thread ever! About one post per minute!!
Mario (or laserlight, or anyone really), where would be a viable situation to use goto. I've read that major loop nesting is a good one. I can't think of any others really.
Oh, I see what you mean. The solution is to use cin.ignore(1000, '\n') instead of just cin.ignore(). Instead of 1000, you could use std::numeric_limits<std::streamsize>::max()In twomers code, if the input has 1 char, it gives one error message, if the input has 2 chars it gives two error messages, and there you go...
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I have seen some good uses of goto, but I don't remember where I saw them.
"The Internet treats censorship as damage and routes around it." - John Gilmore
http://faq.cprogramming.com/cgi-bin/...&id=1043284392Code:#include <limits> using namespace std; int main( void ) { int MAX; while ( (cout << "Input a number please.\n") && !(cin >> MAX) ) { cout << "Error! Input numbers please! (0123456789)\n"; cin.clear(); cin.ignore(std::numeric_limits < int >::max(), '\n'); } }
Well, now it works =]
Thanks for all you guys :P
I looked at this thread for 10 seconds, pressed refresh and 2 new posts!Originally Posted by twomers
"The Internet treats censorship as damage and routes around it." - John Gilmore
(48-23)/25 wow! 1 post per minute
> Mario (or laserlight, or anyone really), where would be a viable situation to use goto. I've read that major loop nesting is a good one. I can't think of any others really.
I can't think two situations of the top of my head.
One is when you want to break completely out of nested loops. a break statement only breaks from the innermost loop. Of course an alternative was to keep a flag and test against it in each loop. But a goto can be important especially on situation where you want to extract every bit of performance out of your loops.
Another is less common... but far more important. When generating code from a grammar through a parser. If you design a script language that generates code in the fly, you will find the use of goto commands quiet useful in your C++ script parser.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
should beCode:return(0)
But this may depend on your environment, I am just stating what is classed as standardCode:return 0
the only place i use goto is to write programs on my calculator and the PIC microprocessor (asm). You should listen to those who urged you to use a loop instead of goto. It is not recommended to use goto since its execution causes an unconditional jump ignoring any type of nesting limitations. goto really does not have a place in structured or object oriented programming.
@cdkiller:
I use goto in graphic programming, for example:
But I do see your point, goto is good at plotting coordinates like above.Code:gotoxy(5,1);cout << "PLOT THIS STRING HERE";
But I have never used it in any sort of "other" C++ programming.