1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

really need your help C++

Discussion in 'C++' started by forsaken, Sep 24, 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. GaneshShinde

    GaneshShinde New Member

    Joined:
    Oct 13, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Sr. Software Engineer
    Location:
    Pune
    This is not exactly what you are asking but I am sure this will help you. :charming:
    Code:
    /* Number or alphabetes detection demo code */
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
     int x = 0;
     string badChars;
     do {
      cout << "Enter a number (-1 = quit): ";
      if(!(cin >> x)) {
       cin.clear();
       cin >> badChars;
       cout << "You typed string \"" << badChars << "\" instead of a number!" << endl;
       cout << "Please try again." << endl;
      } else if(x != -1) {
       cout << "You entered digit!" << x << endl;
      }
     } while(x != -1);
     cin.get();
     return 0;
    }
    
     
  3. GaneshShinde

    GaneshShinde New Member

    Joined:
    Oct 13, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Sr. Software Engineer
    Location:
    Pune
    This link may help you out!
    :2thumbsup
     

Share This Page