Noobie question

This is a discussion on Noobie question within the C++ Programming forums, part of the General Programming Boards category; I am just using it??...

  1. #31
    Noobie
    Guest
    I am just using it??

  2. #32
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    you can just use it like

    Code:
     
     isdigit(1);
    it will return a 0.

  3. #33
    Noobie
    Guest
    but............. the user is entering some number which i have defined as choice and i want choice to be evaluated not 1

  4. #34
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Then you change the 1 to the variable you want tested
    You sure you read the tutorial i posted?

  5. #35
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Jesus, I don't mean to sound mean... but it's not our job to teach you the language. Read a tutorial or something. http://www.cprogramming.com/tutorial.html

    You have MANY errors in your code. Remove the declaration for isdigit at the top of your program.

    Change x = x++; to x++;
    remove x = x;

    Code:
    cin >> choice;
    
    isdigit(choice)
    
    if (dig==0)
    Change that to
    Code:
     
    cin >> choice;
    
    if (isdigit(choice))
    And finally, remove the depricated headers <iostream.h> and <ctype.h>
    Use <iostream> and <cctype> instead.

    So, the top of your program should look like this:
    Code:
    #include <iostream>
    #include <conio.h>
    #include <cctype>
    using namespace std;
    I'm sure there are others, but I quickly looked at your code and those are the ones which stood out.

  6. #36
    Noobie
    Guest
    my code includes isdigit(choice) but the page u referred me to is multiplying two numbers together not asking for a number, evaluating whether the input is really a number, and then and then doing something based on what number was entered, or otherwise re-asking for a number...so like I really dont know what to do

  7. #37
    Noobie
    Guest
    Now the below code will compile, however the screen wont remain up and if i input e it will not do what i want it to do, which is ask me to input until i input 1 or 2

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <ctype.h>
    
    int main()
    {
    
     int choice=0;
      int room;
      int x=0;
      int dig=isdigit(choice);
    
      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;
    
    }

  8. #38
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    No, it won't remain up indeed, put it in a loop.

  9. #39
    Noobie
    Guest
    And the below code here if i enter 3 or e it stops responding instead of asking me to input again

  10. #40
    Noobie
    Guest
    #include <iostream.h>
    #include <conio.h>
    #include <ctype.h>

    int main()
    {

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

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

    cin >> choice;

    if (isdigit(choice))

    cin >> choice;

    else

    while(x==0)

    {

    if(choice==1)
    x++;
    else if(choice==2)
    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;

    }

  11. #41
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    change this

    Code:
     if (isdigit(choice))
    into this

    Code:
     if (isdigit(choice)!=0)

  12. #42
    Noobie
    Guest
    And in the below code-which I believe does contain a loop-isnt that what while is? - it wont compile because it said i never use x but i DO use x

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <ctype.h>
    
    int main()
    {
    
     int choice=0;
      int room;
      int x=0;
    
      cout<<"Please choose a room (1 or 2): ";
    
      while(x==0)
    
        cin >> choice;
    
    if (isdigit(choice))
    
      cin >> choice;
    
        else
    
     {
    
    if(choice==1)
    x++;
    else if(choice==2)
    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;
    
    }

  13. #43
    Noobie
    Guest

    Question

    And with this code it works fine if i enter 1 or 2 but once again with e or 3 it stops responding

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <ctype.h>
    
    int main()
    {
    
     int choice=0;
      int room;
      int x=0;
    
      cout<<"Please choose a room (1 or 2): ";
    
          cin >> choice;
    
    if (isdigit(choice)!=0)     
    
      cin >> choice;
    
        else
    
      while(x==0)
    
    
    
     {
    
    if(choice==1)
    x++;
    else if(choice==2)
    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;
    
    }

  14. #44
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    You seriously need to take some tutorials, that code is a mess,
    and half of it wont work. Plz learn the tutorials provided on this
    website.

  15. #45
    Noobie
    Guest
    I know...i was hoping you would say why it is a mess-the tutorials dont exactly show how to do this...

Page 3 of 4 FirstFirst 1234 LastLast
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, 01:14 PM
  2. A fourth noobie question - namespace std?
    By Noobie in forum C++ Programming
    Replies: 24
    Last Post: 08-12-2005, 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21