Thread: space??

  1. #1
    Unregistered
    Guest

    Question 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....

  2. #2
    Unregistered
    Guest
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 01:30 PM
  3. Replies: 12
    Last Post: 05-17-2003, 05:58 AM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM