-
space??
Hi,
1) I want the user to type in numbers without any spaces
say for eg: user inputs "12 34" .
error should be displayed ........
2) Also if he tried to leave it blank and skip it,then too error should be displayed.
i tried like this
Code:
cin>>num;
while ( num=" ")
{
cout <<"no blanks allowed ";
cout<<"please re-enter"
cin>>num;
}
but unsuccessful.......can any one suggest me the right way of solving the above 2 Qs.
Sorry,but Ir eally new to this programminf stuff,and I appreciate if u all gurus out there ,give me a helping hand...thanks....
-
If you do that it will be taken as a single number input. ie if you enter 1234, num will equal 1234. If thats what you want then thats fine and the extraction operator will ignore any preceeding spaces. Anything after the number will also be ignored, including more spaces. If you then want to separate the digits you will need to use the modulus operator.
Another idea is to input them as characters and check for spaces that way. Easy enough but it might not be what you want.