1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

really need your help C++

Discussion in 'C++' started by forsaken, Sep 25, 2011.

  1. forsaken

    forsaken New Member

    Joined:
    Sep 24, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I just started to study the C++ Programming Language. I'm done with the condition statements and jump statements. An idea came to my mind to create a simple program
    that will determine if the input is a character or integer.
    For example, the program asks you "How old are you?" and then you input a character (A-Z), the program will output "Your input is a Character."
    Same as, if the program asks you "Choose a letter from A-Z" and then you input a integer (0-9), the program will output "Your input is a Integer."

    Your reply will be a really big help to me as I study C++.

    Thanks..
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    If you use a function like fgets this will help you do what you want. Then you just have to inspect the contents of the string for the characters, e.g.
    Code:
    if (inputstr[0]>='0' && inputstr[0]<='9')
      printf("You entered a number\n");
    else if (inputstr[0]>='A' && inputstr[0]<='Z')
      printf("You entered a capital letter\n");
    
     

Share This Page