Thread: Noobie question

  1. #16
    Noobie
    Guest
    with the above code-it works fine if i enter 1 or 2 and if i enter 3 it wants for another input but if i enter e then it quits responding

  2. #17
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    To prevent that you need to add to your program. Take the entered data and validate it. ie check if it is a number etc. Use isdigit() or something similar.
    Last edited by Fountain; 01-20-2003 at 03:18 PM.
    Such is life.

  3. #18
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by Noobie
    but if i enter e then it quits responding
    Yeah, well thats because it stores in int's and it cant
    store letters in int's, try replacing int with char at every variable

  4. #19
    Noobie
    Guest
    isdigit() -- all i know is it appears to be a function but what to do with it?

  5. #20
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640

  6. #21
    noobie
    Guest
    it says that isdigit returns 0 if the thing is an integer but how do i tell what it returns and how do i tell it what to evaluate

  7. #22
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Im not really formiliar with isdigit(), but i suspect the 1 argument
    you pass in, is the argument you want to test to see if it's an
    char or an int, if an zero if its not an int and a non-zero if its
    an int.

    You can't change what it returns, why should you?

  8. #23
    Noobie
    Guest
    Its just that I dont know how to pass an argument into a function and I dont know how to get what code I already have to work, let alone to bring in this function which I have not a clue how to fit into the code I already have

  9. #24
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    If you're not familiar with functions i redirect you here

  10. #25
    Noobie
    Guest
    int isdigit(int choice)

    is that what i use?

  11. #26
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Yes, that's what the document i posted earlyer said.

  12. #27
    Noobie
    Guest
    So it gives me a 0 or a 1--what can i do with that?

  13. #28
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Then you know if an int has been inputted or a char.

  14. #29
    Noobie
    Guest
    This doesnt work

    [copy]
    #include <iostream.h>
    #include <conio.h>
    #include <ctype.h>

    int isdigit(int choice);

    int isdigit(int choice)

    {

    return dig;

    }


    int main()
    {

    int choice;
    int room;
    int x=0;
    int dig=0;

    cout<<"Please choose a room (1 or 2): ";

    cin >> choice;

    isdigit(choice)

    if (dig==0)

    cin >> choice;

    else

    while(x==0)

    {

    if(choice==1)
    x=x++;
    else if(choice==2)
    x=x++;
    else
    x=x;
    }

    if(choice==1)

    {

    room=1;
    cout<<"You enter a room\n";

    }

    else if(choice==2)

    {
    room=2;

    cout<<"You are in room 2\n";

    }

    else

    {

    cout<<"You should not see this.\n";

    }

    if (room==1)
    {
    cout<<"Yep";
    }
    else if (room==2)
    {
    cout<<"Nope";
    }
    else
    {
    cout <<"I need to know how to ask them to plz enter a proper room choice, but how to do that? i don't know.";
    }

    return 0;

    }

    [/copy]

  15. #30
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    isdigit() is already made for you, you can just use it.
    it's code by the way not copy

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. A fourth noobie question - namespace std?
    By Noobie in forum C++ Programming
    Replies: 24
    Last Post: 08-12-2005, 02:10 PM
  3. another noobie question
    By noobie in forum C++ Programming
    Replies: 21
    Last Post: 01-21-2003, 02:04 PM
  4. A third noobie question
    By Noobie in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2003, 12:53 AM