Thread: Void returning functions.

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    4

    Void returning functions.

    Hello, I'm using NetBeans 6.9 on GNU/Linux (Ubuntu 10.10)

    When I run this,

    Code:
    #include <iostream>;
    
    using namespace std;
    
    void showname();
    void showage();
    
    
    int main(){
    
        showname();
        showage();
    
        return 0;
    }
    
    void showname(){
        int name;
    
        cout << "What is your name?" << endl;
        cin >> name;
        cout << "Your name is " << name << endl;
    }
    
    void showage(){
        int age;
    
        cout << "What age are you?" << endl;
        cin >> age;
        cout << "You are " << age << " years old." << endl;
    }
    ..all I get is..

    "Your name is 0
    What age are you?
    You are 0 years old."


    when I enter my name. Please help (It should be obvious what output I'm expecting to get)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > int name;
    Are you a number?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Are you a number?
    Yes? (My name is Zero.)

    Oh, wait, you were telling him to be more mindful of his code when it is is copied and pasted.

    Soma
    Last edited by phantomotap; 05-31-2011 at 11:29 PM. Reason: This is a joke! (12:49)

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    4
    Quote Originally Posted by Salem View Post
    > int name;
    Are you a number?
    Thanks, Salem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C void functions-- help please?
    By shane981 in forum C Programming
    Replies: 3
    Last Post: 03-28-2008, 07:07 AM
  2. Void Functions
    By MyntiFresh in forum C++ Programming
    Replies: 10
    Last Post: 07-13-2005, 06:47 AM
  3. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  4. function returning void
    By studentc in forum C Programming
    Replies: 14
    Last Post: 05-13-2004, 04:55 PM
  5. Returning a Tree node back to void main()
    By gazza in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2002, 02:48 AM