Thread: What does it mean when a integer variable has a word value

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    114

    What does it mean when a integer variable has a word value

    hello thier guys i just started learning programing langauge today so i have a few questions that the tutorials im using dont tell me
    K so lets say this is the program
    Code:
    //Including Cout function
    #include <iostream>
    //Using standard library
    using namespace std;
    
    int main()
    {
      int password;
    
      cout<<"Please enter the password: ";
      cin>> password;
      cin.ignore(); // wat does this Piece of code mean?
      cout<<"You entered: "<< password <<"\n";
      cin.get();
    }
    K lets say the user types in potion i got the reply back you typed in
    2147340288

    How does Potion = 2147340288?

    Thanks matsp and MacGyver
    Last edited by Nathan the noob; 06-26-2008 at 02:49 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It would be more likely that since integer input only accepts numerical input, that your input actually failed, and your variable contains the old value it had before the attempt to input it - which, since you don't actually set it, could be any value (but it will most likely be the same each time you run the code, at least until you change something in the code).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I would guess that it's because it's expecting an int.

    As far as cin.ignore() goes, it reads a char from the input buffer and discards it. It's used at times to eliminate the trailing '\n' left in the buffer by some read operations.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. A pointer question.
    By joenching in forum C++ Programming
    Replies: 7
    Last Post: 03-20-2008, 04:10 PM
  3. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM