Thread: Not working code

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    46

    Not working code

    Code:
    intmain()
    {
    cout<<"please enter your first_name and age\n";
    string first_name;
    int age;
    cin>> first_name;
    cin>> age;
    cout<< "Hello," << first_name << "(age " << age << ")\n";
    
    
    return 0;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,923
    Uh, isn't this roughly the same issue as trying to write a code where I can enter a name and then it says hi, your_name??

    Aside from that, when you post "not working code", you must say how does it not work.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2019
    Posts
    46
    Quote Originally Posted by laserlight View Post
    Uh, isn't this roughly the same issue as trying to write a code where I can enter a name and then it says hi, your_name??

    Aside from that, when you post "not working code", you must say how does it not work.
    Yes, you were right. But why is the book I am using have that code that I wrote? It changes frequently. Out of curiosity is all code written in c++ suppose to #include and the like?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,923
    Quote Originally Posted by solidusMGS
    But why is the book I am using have that code that I wrote?
    Perhaps the book author expected you to write in the header inclusions and write a using directive at file scope.

    Quote Originally Posted by solidusMGS
    Out of curiosity is all code written in c++ suppose to #include and the like?
    Yes. Well, you don't absolutely need to include headers, but then it means that either you're not using anything externally defined (unlikely), or you're declaring them manually yourself (poor practice because it risks getting it wrong).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why is this code not working?
    By Owais in forum C Programming
    Replies: 5
    Last Post: 04-06-2014, 06:09 AM
  2. why is my code not working from here it looks ok
    By Lisa_townsend in forum C Programming
    Replies: 19
    Last Post: 12-05-2009, 12:08 PM
  3. my code is not working
    By turbot in forum C Programming
    Replies: 3
    Last Post: 01-28-2009, 05:23 AM
  4. Help Code Is Not Working
    By srivatsan in forum C++ Programming
    Replies: 23
    Last Post: 11-12-2008, 12:30 PM
  5. Non-Working Code
    By SheilahT in forum C++ Programming
    Replies: 9
    Last Post: 09-19-2006, 04:04 PM

Tags for this Thread