isdigit not working?
Results 1 to 2 of 2

Thread: isdigit not working?

  1. #1
    Member
    Join Date
    Feb 2003
    Posts
    78

    isdigit not working?

    Yeah, Back to my Lyrics database. I have my class all sorted out, works great. Now I am on to my actual program. I started putting songs and lyrics into text files, but it is very time consuming. I only have five cds done, about 60 maybe 70 songs. I plan on having all the 'punk' songs I have ripped on my computer...which totals to 481 at the moment. Side note: I have bought all of these cds... no illegal downloading... just ripping cds I bought. Anywayz, Because this is a fun program and not required, I want to make it the best it can be. (Weird how that works, when it is required...you dont really care to error trap everything...unless it is for you job I guess :-\) So I am using isalpha and isdigit to make sure that what the user enters is the correct data type, because otherwise it throws them in a infinite loop. Well, I got the isalpha to work great...but I cant get isdigit to work. I am wondering if I am using it wrong, or what. I got the syntax and what is exactly does off my Computer Science 120 class website. So I figured it would be correct. Anywayz...enuff talking and more code. Help!

    Code:
    void ask()
    {
        int choice;
        char quit;
        
        cout<<"***************| Epison07's Lyrical Database |***************\n";
        
        do{
        cout<<"\n\nHow would you like to find your lyrics?\n";
        cout<<"1. Search Alphabetically\n2. Search by Group Name\n";
        cout<<"3. Search by Song Title\nChoice : ";
        cin>>choice;
        if(isdigit(choice) == false){
            cout<<"\nInvald choice!\n";
            continue;
        }    
    
        if(choice == 1)    alpha();
        else if(choice == 2)    group();
        else if(choice == 3)    song();
        else{
            cout<<"\nInvald choice!\n";
            continue;
        }    
    
        cout<<"\n\nPress any key to continue\nPress 'x' to quit\n";
        cin>>quit;
        if(isalpha(quit) == false) continue;
        }while(quit != 'x');    
        return;
    }
    Like I said, isalpha works great. But isdigit doesnt seem to work. If I enter a number, it is supposed to return true, otherwise false...correct? Well I dont understand why this dont work. I tried negating(?) the if statement, but that didnt help. If you have a C++ compiler and can help me out with this, that would be great. It has been bugging me for a day or two now.
    Thanks in advance
    -Ep
    01001001001000000100110001101111011101100110010100100000010000100110010101110100011101000111100100100001

  2. #2
    Super Moderator
    Know-it-All Master Beaver

    Join Date
    Jan 2003
    Posts
    3,914
    Hey Hey,

    I'm assuming you've included ctype.h??

    Anyways... I'm not much of a C++ programmer... but what if you did

    [code]
    if(isdigit(choice)) {
    if(choice == 1) alpha();
    else if(choice == 2) group();
    else if(choice == 3) song();
    else{
    cout<<"\nInvald choice!\n";
    continue;
    }

    cout<<"\n\nPress any key to continue\nPress 'x' to quit\n";
    cin>>quit;
    if(isalpha(quit) == false) continue;
    }while(quit != 'x');
    return;
    }
    else {
    cout<<"\nInvald choice!\n";
    continue;
    }


    This should work for ya... (as far as I understand the language)...

    Peace,
    HT
    IT Blog: .:Computer Defense:.
    PnCHd (Pronounced Pinched): Acronym - Point 'n Click Hacked. As in: "That website was pinched" or "The skiddie pinched my computer because I forgot to patch".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides