Thread: basic input

  1. #1
    Mmm. Purple.
    Join Date
    May 2002

    Arrow basic input

    i have this code:
    cout<<"level number:";
    it goes it loops of itself if u input wildcards or chars
    how would i stop it doing this ie return an error saying incorrect levnum?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Read a string instead of whatever levnum is now and validate it by checking the length of the string and that each element matches a digit and that the number is within your range for levels, then convert it to an integer with atoi.

    My best code is written with the delete key.

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001

    Post Use isdigit()!

    After you get the input do this:

    #include <ctype.h>

    // Is a digit
    cout << "Must be digit!";


    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  2. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM