Thread: Question about small tutorial closing

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    Question about small tutorial closing

    I am reading through a C++ book, and for one of the tutorials I must write a program that displays my Name, Social Security, and Date of Birth. Sounds easy enough, right? Well, I want a program that takes what the user inputs, and outputs those things! But, it seems to not work, and I cant figure out why its not working! It just closes right away after running through the program (or if i use cin.get() it dosent do anything!) Please help!

    Code:
    #include <iostream>
    
    using namespace std;
    int name;
    int socialsecurity;
    int dob;
    int main( )
    {
    cout<< "What is your name?: ";
    cin>> name; // Stores the answer in the variable name
    cin.ignore();
    cout<< "What is your social security?: "; // Will ask you for your social security
    cin >> socialsecurity;
    cin.ignore();
    cout<< "What is your date of birth?: ";
    cin.ignore();
    cin >> dob;
    cout<< "Your name is " << name << ", your SSN is " << socialsecurity << ", your dob is " << dob;
    return 0;
    }

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    name should not be int, it puts cin into trouble.

    [EDIT]
    You should tell the user the format of date which the program accepts.
    2006/3/3
    2006 3 3
    etc
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    There is a FAQ entry about this issue here. Check there and search the boards before you post.

    You will also want to look up the std::string class for the name. For the date you can either use three ints (day, month, and year) or a string if you'd rather have it inputted as mm/dd/yy or something like that. The SSN will work as an int or string since you're not doing any calculations with it.
    There is a difference between tedious and difficult.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    5
    Thank you! You are a life saver!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question about the C programming tutorial #1
    By elsheepo in forum C Programming
    Replies: 13
    Last Post: 01-19-2009, 08:59 PM
  2. New to C, small compiler question
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 12-31-2005, 02:16 AM
  3. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  4. A small Question
    By CodeJerk in forum C++ Programming
    Replies: 2
    Last Post: 11-20-2002, 09:08 AM
  5. small HTML question
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-18-2001, 06:42 AM