Thread: letters

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    26

    letters

    if a program wants you to enter a number, if you were to happen to enter a letter is there any way to make the program say something like "hey you idiot i said number" THX!!

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is isdigit().

    Kuphryn

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Another way might be string streams.

  4. #4
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Code:
    #include <iostream.h>
    
    int main()
    {
       int digit;
       
       cout << "Enter a number: ";
       cin >> digit;
       
       if(cin.fail())
       {
          cin.clear(1);
          cin.ignore(80, '\n');
          
          cout << "Hey you idiot! I said number." << endl;
       }
       
       return 0;
    }
    Or something similar
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  5. #5
    Student Forever! bookworm's Avatar
    Join Date
    Apr 2003
    Posts
    132
    I agree with Ronin.
    Use If then or Switch statements. They are easy and hassle-free.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating random letters
    By ominub in forum C Programming
    Replies: 6
    Last Post: 04-29-2009, 01:12 AM
  2. need to count individual letters in input
    By epox in forum C Programming
    Replies: 12
    Last Post: 05-22-2006, 06:32 AM
  3. Counting letters and digits
    By FeNCinGeR in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2006, 11:39 AM
  4. drive letters
    By metsman20 in forum Tech Board
    Replies: 4
    Last Post: 12-11-2003, 12:54 PM
  5. Switching letters
    By XiReDDeViLiX in forum Windows Programming
    Replies: 4
    Last Post: 06-06-2002, 06:48 AM