Problem with simple error checking

Scratch the error checking bit. The original code involved error checking, but I've dwindled the problem down to the following code:
int input;
cout << endl << "Enter number: ";
cin >> input;
if (isnumber(input) == 0)
cout << "Not a number";
else
cout << "Is a number";
How is it that, when I enter the number 2 as input for this program, I get the response "Not a number." I get the same response when I enter something that actually is not a number, like the character 'a', as input. No matter what, it displays "Not a number."
This seems really basic to me. Am I missing something obvious here?

As far as isnumber() goes, I made a mistake. Apparently isnumber() is also a function because it didn't raise an error, but it was a typo -- the function I meant to use was isdigit(), not isnumber(). So, I changed the function isnumber() to isdigit(), but still got the exact same result.
I've since figured out what the problem is, though. The function isdigit() was given in the notes my professor provided, along with isalpha(), ispunct(), isspace(), isupper(), and islower(). It occurred to me that these functions are intended to be used with single characters, and in my code I had defined the variable input as an int. So, I changed input to data type char and it worked fine.
So, that solves that issue, but raises another. Consider the following code, if you will:
int numHands;
while (numHands < 1 || numHands > 7)
cout << endl << "How many hands do you want to play: ";
cin >> numHands;
if (numHands < 1)
cout << endl << "You must play at least one hand...";
wait();
else if (numHands > 7)
cout << endl << "You can not play more than seven hands...";
wait();
This is a simple bit of error checking to make sure that the number that the user enters is between 1 and 7, and in that regard, it works fine. It does not, however, ensure that what the user enters is a number in the first place. My original solution to this was the following code:
while (numHands < 1 || numHands > 7 || isdigit(numHands) == 0)
cout << endl << "How many hands do you want to play: ";
cin >> numHands;
if (numHands < 1)
cout << endl << "You must play at least one hand...";
else if (numHands > 7)
cout << endl << "You can not play more than seven hands...";
else if (isdigit(numHands) == 0)
cout << endl << "You did not enter a number...";
When this didn't work, it prompted me to post this thread, but as I mentioned at the beginning of this post, I realized that the reason it didn't work was because isdigit() works with char and not int data types, and I obviously can't declare numHands as a char because the user could enter more than one character as input.
How, then, can I error check to ensure that the user's input is, in fact, a number?

Similar Messages

  • Has anyone had a problem with depositing a check with the app for Bank of America?

    Has anyone had a problem with depositing a check on a bank app?

    Is the check something like a payroll check where its digitally printed and all in text?, or is it a handwritten check?
    from my experience handwritten checks rarely work, myself and friends have always recieved an error stating the picture was to blurry no matter how many times we took a picture. From what i have read with others who have issues with depositing handwritten checks, some checks are deemed to blurry based on the handwriting, therefore the app wont accept the check, while other handwritten check will be accepted just fine, i hope this resolves your issue's and concerns

  • TS1702 Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

    Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

    Hello, I,m having problems with Polish spell check. It says in iPnstruction that this App (pages) should show my writing mistakes. Check spell button is on but but check spell is not working. Need help Please.

  • Hello ! I'm using iphone 5 running ios 7.1.1 I have problem with Appstore error and also Safari don't work too. What can I do to fix this problem ?

    Hello ! I'm using iphone 5 running ios 7.1.1 and I have problem with appstore error and also Safari doesn't work. what can do I fix this problem ? I need help now my iphone can't do nothing

    Need more details. What is your appstore error exactly? and what happens when you try to use Safari?

  • Problems with simple picture gallery

    I've got a website project where the client wanted a picture
    gallery. I don't really do much with Flash so I went on the web and
    found a tutorial on how to get what I want. Problem is that the
    instructions I followed are fairly old so I couldn't export my
    movie any higher than AS2 and Flash 6 and have it work. That would
    be fine except that I wanted to use a feature that requires Flash 8
    or higher, namely a gradient mask. I was hoping that I could post
    my code and have the board gurus help me out with what i need to do
    to get everything working together.
    First you'll want to create a movie using AS2 and Flash 8 to
    see what I'm trying to accomplish, then export it again with Flash
    6 to see it actually working. You can grab a copy of what I'm
    working with here:
    http://www.technospider.com/~david/rusty.zip
    All help greatly appreciated.
    Thanks,
    David

    based on experience. i didn't check your file.
    you're not likely to get anyone in this forum to check your
    file.
    if there's not code problem, and you can't publish for flash
    8, there will be an error message. if you can publish for flash 8,
    you see no error message but your application fails to work
    correctly, you must have a problem with code.

  • Latest iTunes update problems with repeated error messages every 65 seconds??

    After this mornings' update of iTunes.  Problems with Applemobiledeviceservices.exe.  Error message every 65 seconds - software exception (oxc06d007e) occurred in the application at location 0x7c812fd3.
    How do I stop this?

    'The installer has insufficient privileges to modify this file C:\Program Files (x86)\Common Files\Apple\Apple Application Support\Web kit.resources\inspector\Images\Spinner Inactive Selected.gif.'
    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    XP instructions in the following document: How to perform disk error checking in Windows XP
    Vista instructions in the following document: Check your hard disk for errors
    Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • After installing firefox 4.0 I've been having problems with rundll error on startup. Norton scan is finding a high risk malware.

    Last week I installed firefox 4.0 beta & the next time the computer was restarted a rundll error window appeared that said windows cannot locate file. This file showed up in the startup programs. When norton finds this which is every 1 or 2 days it removes it after a restart but the error & malware comes back. I went back to firefox 3.6 but still have this problem. Can you help?
    Thanks, Dennis

    It seems unusual that Norton should block and remove firefox updates. Having said that I was posting in a thread about problems with Norton a few days ago see [https://support.mozilla.com/en-US/questions/789617#answer-143767 thread] ''"I down loaded fromFFox the latest down - norton 360 - stopped the down load - stated not to use it - asked to stop running the program - I click yes thinking a problem now on my other computer I cant use FFox as a Browers -"''
    I use Norton (NIS) and received only a mild advisory on one Firefox update. I have Windows XP with Firefox3.6.15 & 4RC installed

  • Problem with call error / call restart

    If during a call with the Bluetooth car speakerphone on and - due to loss of signal, or anything else - I get a call error, in the lock screen there is a message of error with black color font and (!) icon, and until there is nothing strange, right? But next, if I try to unlock the iPhone the lost call restart automatically even if I would not to do it..
    Is there anyone with such a problem? Any solutions?

    I encounter a similar problem with 9.1.1.
    My problem is link to this bug ID : CSCtq10477.
    Mathieu

  • Problem with simple chart

    Hi everyone. I've got a problem with ABAP charts. I need to place a simple chart in screen's container.
    REPORT ZWOP_TEST4 .
    Contain the constants for the graph type
    TYPE-POOLS: GFW.
    DATA: VALUES       TYPE TABLE OF GPRVAL WITH HEADER LINE.
    DATA: COLUMN_TEXTS TYPE TABLE OF GPRTXT WITH HEADER LINE.
    DATA: ok_code LIKE sy-ucomm.
    DATA: my_container TYPE REF TO cl_gui_custom_container.
    REFRESH VALUES.
    REFRESH COLUMN_TEXTS.
    VALUES-ROWTXT = 'Salary'.
    VALUES-VAL1 = 50000.
    VALUES-VAL2 = 51000.
    APPEND VALUES.
    VALUES-ROWTXT = 'Life cost'.
    VALUES-VAL1 = 49000.
    VALUES-VAL2 = 51200.
    APPEND VALUES.
    COLUMN_TEXTS-COLTXT = '2003'.
    APPEND COLUMN_TEXTS.
    COLUMN_TEXTS-COLTXT = '2004'.
    APPEND COLUMN_TEXTS.
    Call a chart into a standard container, this function could be used
    for many different graphic types depending on the presentation_type
    field :
    gfw_prestype_lines
    gfw_prestype_area
    gfw_prestype_horizontal_bars
    gfw_prestype_pie_chart
    gfw_prestype_vertical_bars
    gfw_prestype_time_axis
    CALL SCREEN '1000'.
      CALL FUNCTION 'GFW_PRES_SHOW'
        EXPORTING
          CONTAINER         = 'CONTAINER'    "A screen with an empty
                                            container must be defined
          PRESENTATION_TYPE = GFW_PRESTYPE_LINES
        TABLES
          VALUES            = VALUES
          COLUMN_TEXTS      = COLUMN_TEXTS
        EXCEPTIONS
          ERROR_OCCURRED    = 1
          OTHERS            = 2.
    *&      Module  STATUS_1000  OUTPUT
          text
    MODULE STATUS_1000 OUTPUT.
      SET PF-STATUS 'GUI_1000'.
    SET TITLEBAR 'xxx'.
      IF my_container IS INITIAL.
        CREATE OBJECT my_container
          EXPORTING container_name = 'CONTAINER'.
      ENDIF.
    ENDMODULE.                 " STATUS_1000  OUTPUT
    *&      Module  USER_COMMAND_1000  INPUT
          text
    MODULE USER_COMMAND_1000 INPUT.
      ok_code = sy-ucomm.
      CASE ok_code.
        WHEN 'EXIT'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_1000  INPUT
    I created a screen 1000 in SCREENPAINTER, named it 'CONTAINER'. Then I try to launch code above and nothing appears on the screen. Could You give me some tip?

    Hi,
    delete this lines:
    IF my_container IS INITIAL.
    CREATE OBJECT my_container
    EXPORTING container_name = 'CONTAINER'.
    ENDIF.
    then it should work.
    R

  • Problem with simple query

    I have a problem with Oracle 10.2.0.5.0 and 11.2.0.1.0. Query result is wrong.
    SELECT t.id
      FROM (SELECT t.ID, MAX(t.nom) AS nom
              FROM (SELECT 2 AS ID, 200 AS nom
                      FROM dual
                    UNION ALL
                    SELECT 3 AS ID, 0 AS nom FROM dual) t
              LEFT JOIN (SELECT 0 AS ID_1, 0 AS nom_1 FROM dual) s
                ON s.id_1 = t.ID
             WHERE t.ID IN (2, 3)
             GROUP BY t.ID
            HAVING MAX(t.nom) != 0) t;Return nothing.
    But on Oracle 10.2.0.4.0 result is correct:
    ID  NOM
    2  200

    Looks like a bug related to ANSI joins.
    Check Oracle Support, maybe it's fixed in 11.2.0.2.
    It works with Oracle join syntax :
    Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
    Connected as dev
    SQL>
    SQL> SELECT t.id
      2    FROM (SELECT t.ID, MAX(t.nom) AS nom
      3            FROM (SELECT 2 AS ID, 200 AS nom
      4                    FROM dual
      5                  UNION ALL
      6                  SELECT 3 AS ID, 0 AS nom FROM dual) t
      7                ,(SELECT 0 AS ID_1, 0 AS nom_1 FROM dual) s
      8           WHERE t.ID IN (2, 3)
      9           AND s.id_1(+) = t.ID
    10           GROUP BY t.ID
    11          HAVING MAX(t.nom) != 0) t;
            ID
             2

  • Problem with OSCP revocation checking

    Hi,
    since patch 10.1.3 we have a problem with Adobe Reader on englisch OS (xp sp3 and win7, all MS Updates installed).
    We use a software deployment system to install Adobe Reader and preset some preferences for signing pdf documents (preferences/security/advanced preferences/windows integration -> all three boxes checked).
    When a user opens Adobe Reader there is a process starting after about 10 seconds to check certificate revocation and a small progress window appears:
    Contacting http://oscp.verisign.com for OSCP based revocation checking, press ESC to cancel
    With this process starting the CPU load rises to 99% on a single core or 50% on a dual core and Adobe Reader is frozen.
    Unchecking the revocation checking (preferences/security/advanced preferences/verification -> Require certificate revocation...) is not an option due to security reasons.
    Patch 10.1.4 didn't fix this problem. Interestingly we don't have this problem on our computer with german OS and german Adobe Reader.
    Any ideas?
    greetings
    DJWG49

    Hi,
    since patch 10.1.3 we have a problem with Adobe Reader on englisch OS (xp sp3 and win7, all MS Updates installed).
    We use a software deployment system to install Adobe Reader and preset some preferences for signing pdf documents (preferences/security/advanced preferences/windows integration -> all three boxes checked).
    When a user opens Adobe Reader there is a process starting after about 10 seconds to check certificate revocation and a small progress window appears:
    Contacting http://oscp.verisign.com for OSCP based revocation checking, press ESC to cancel
    With this process starting the CPU load rises to 99% on a single core or 50% on a dual core and Adobe Reader is frozen.
    Unchecking the revocation checking (preferences/security/advanced preferences/verification -> Require certificate revocation...) is not an option due to security reasons.
    Patch 10.1.4 didn't fix this problem. Interestingly we don't have this problem on our computer with german OS and german Adobe Reader.
    Any ideas?
    greetings
    DJWG49

  • Problem with repair error 1311, and trouble reinstalling.

    I am having problems with reader, so I tried to do a repair but got error 1311. I uninstalled not im having trouble reinstalling...

    Error 1311, 1335, or 2350 "Source file not found...data1.cab" |Install Adobe products | Windows

  • Iphone problem with itunes error 1603 on restore

    I allowed my iphone battery to fully discharge and upon recharging got the error message with a large exclamation mark “please connect to itunes”. When I connected to itunes I was told that the phone was in recovery mode and needed to be reloaded. Itunes went out and downloaded the new firmware and began the install process after I approved the input screen that said it would wipe out all my data. 1/3 of the way through the process I received a message box that told me the process had failed to restore the iphone for an unknown error (number 1603).
    After looking online and calling ATT as well as Apple the best solution I received was to send the iphone in for replacement (i am 5 hours from an apple store). After fiddling around I have managed to solve the problem on my own.
    After trying everything else with no results, I pulled the SIM card out of the iphone and plugged the iphone into my computer. Itunes then reloaded the software and firmware successfully. I then put the SIM card back in and synced it up with itunes and it asked me to confirm the resync. Afterwards it just worked fine.
    My iphone works again!

    "1- suddenly my iPhone 5 lost mobile company signal and word searching appears instead but no signal for the hole day so I changed the sim with other provider and since it gave me the same result I searched the web and the seems no solution other than restore.
    I did restore and update to iOS 7.0.4 but at the restore takes at the last 1% in the last moment of restore it will take loooong time then gave me error 3. And now for more than a month the iPhone stuck with recovery logo. Almost I tried every trick in the book . Change USB cable, port, PC. PC with other OS . Even freezing the iPhone as I read here noooooo result the same happened again and again."
    I have exactly the same problem with my iPhone 5s!

  • TS3694 what is a problem with this error (3194)

    I have a problem with my iphone. I want to update my version 5.0.1 to 6.0.1 and we see this error 3194. What I need to do?

    I'd start here
    http://support.apple.com/kb/TS3694

  • Problem with ipad error 9

    I'm having problems with restoring my ipad. Error 9

    Have you had a look at http://support.apple.com/kb/TS1275? It suggests Error 9 is a USB issue, so you can try other USB ports, perhaps a different cable, or even trying to restore on another computer, if you have one to hand.
    Hope that helps,

Maybe you are looking for

  • Ssrs security access for users on a different domain

    Hi We are using ssrs 2008 r2 and have added a new domain to our network as we are working with another company. Our original domain was say "DomainA" which can access all our reports, how do we give access to the new domain "DomainB" access to our re

  • Can't view slideshow

    I have a site that I built to show work I have done. The samples are in photo albums. Someone just told me that when they click on the slideshow option, it comes up blank. Anyone else finding that problem? Thanks

  • Performance and HA for HttpClusterServlet

              Hi,           I didn't see much information in the documentation about the HttpClusterServlet:           - can it be (easily) set up in a HA configuration (to avoid it being a SPOF)?           - how does it perform?           - is it possib

  • String Trim

    Hello, I'm new to Java programming, I have programmed in other languages. Heres my problem: At the console someone enters say... "monkee1;monkee2;monkee3 -a -b -c" how can i trim it to just "monkee1;monkee2;monkee3 -a -b -c" getting rid the white spa

  • HGrid hide the Action icon for Root Node

    Hi, I have a Hgrid developed. It contains a column called "Action" against all the nodes. I need to hide this icon only for the Root Node. Can anyone please suggest a solution? Thanks in Advance! Cheers., Hem