Void returning functions.

This is a discussion on Void returning functions. within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm using NetBeans 6.9 on GNU/Linux (Ubuntu 10.10) When I run this, Code: #include <iostream>; using namespace std; void ...

  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
    32,851
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,415
    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; 06-01-2011 at 12:29 AM. 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, 08:07 AM
  2. Void Functions
    By MyntiFresh in forum C++ Programming
    Replies: 10
    Last Post: 07-13-2005, 07:47 AM
  3. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 06:30 PM
  4. function returning void
    By studentc in forum C Programming
    Replies: 14
    Last Post: 05-13-2004, 05:55 PM
  5. Returning a Tree node back to void main()
    By gazza in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2002, 03:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21