+ 1
Plz help me with this code!? when i write this code there is no compiler error but i end up with endless lope
int num; x:for(;cin>>num;){ //some code //this for built so it won't end and keep taking numbers } cout <<"this is not a number plz enter a number"; goto x; so when the user enter a string instead of a number it enter an endless loop . how do i break this , and make it say enter a number without ending the program or initializing an endlees loop.
1 Answer
+ 1
You haven't entered the test expression which checks and continue the loop that is the limit of loop that is the reason your loop is going endlessly.
To enter a string you should use an array of maximum size as you prefer and use cin.getline to input the string.