Thread: Conversion, atoi (apologies, searches have been done)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    edit: never mind. Handled by others.
    Last edited by FillYourBrain; 10-13-2004 at 02:19 PM.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    24
    Yes I want to populate an array with 5 numbers (between 0-9) and check that the user only enteres a number between 0 and 9, then read it out backwards.

    Best regards, global

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    ooops. sorry 'bout that. Thank you misplaced.

    You don't need to convert the input to a char to check that user input only values 0-9. You can use an array of int. Use a loop to get the ints. Check that input is in the range you want. Store each input in the array in order they are received. Print them out backward using a loop starting at last valid index and decreasing loop counter each loop through.

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    24
    Yes, but what if the user enters a letter by mistake?

    Thanks for your help, global

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by global
    Yes, but what if the user enters a letter by mistake?

    Thanks for your help, global


    *i believe there is a function/macro call isalpha()...
    if you're using an ide with documentation look in the help index for it
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Input validation by accepting input as a string and converting after validation or by using the cin.fail(), cin.good(), cin.ignore(), cin.clear() methods are both valid. Whichever way you feel more comfortable should work.

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    24
    How would i convert it after validation? If i want to input 5 numbers as characters. check convert it, check that it is above 0 and below 9 - how would this be done. I thought this would be easy, but people just say 'convert' - but i have yet to achieve this.

    I do appreciate your help.

    Regards, global

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  4. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 09:44 PM
  5. string to int conversion not using atoi()
    By linucksrox in forum C Programming
    Replies: 2
    Last Post: 05-19-2004, 12:17 AM