Thread: Help with functions!!!!

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Lightbulb Help with functions!!!!

    I have three warnings on this program:

    #include <iostream.h>

    int get_month ();
    int get_day ();
    int get_year ();
    int display (int,int,int);

    void main ()
    {
    int dia, mes, anos;
    dia=get_day ();
    mes=get_month ();
    anos=get_year ();
    display(dia,mes,anos);
    return;
    }

    int get_day ()
    {
    int i;
    cout << "\nPlease enter day of brith ";
    cin >> i;
    return i;
    }
    int get_month ()
    {
    int hate;
    cout << "\nPlease enter month of brith ";
    cin >> hate;
    return hate;
    }

    int get_year ()
    {
    int functions;
    cout << "\nPlease enter year of birth ";
    cin >> functions;
    return functions;
    }

    int display (int dia, int mes, int anos)
    {
    cout << "";
    return 0;
    }


    I cant find the problem, please help.

  2. #2
    Registered User f0ul's Avatar
    Join Date
    Nov 2001
    Posts
    37

    wehey .. I know this one!

    the fault is that u don't need a return if u have declared a void!

    line 15 has a return - delete it and it will compile!

    hope Im right!!
    I don't want to belong to any club that'll accept me as a member!

  3. #3
    Unregistered
    Guest
    It compiles and runs fine for me as it is.

    If you have a void function but don't place an expression after the return then you are essentially saying return void, which is legal in C++. However, void main() is a nonstandard function, the ANSI standard defines that main should be called as an int, like so:
    Code:
    int main(void){
        //code
        return 0;
    }

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    ok

    The program does run however, once the year is entered the program stops. So I am thinking that there is something wrong with:
    int display (int dia, int mes, int anos)
    {
    cout << "";
    return 0;
    }

    I get the following warning:


    Compiling YYYPG6_1.CPP:
    Warning YYYPG6_1.CPP 50: Parameter 'dia' is never used in function display(int,int,int)
    Warning YYYPG6_1.CPP 50: Parameter 'mes' is never used in function display(int,int,int)
    Warning YYYPG6_1.CPP 50: Parameter 'anos' is never used in function display(int,int,int)
    this part:

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Well yeah...your passing those 3 params, but doing nothing with them...

    The compiler issuiong warnings in that way is like it saying "what was the point of passing them?"

  6. #6
    Unregistered
    Guest

    U Need to pause the system

    The program is working after you have the user enter the year. However, it works so fast that it displays it and closes the window immediately after. To combat this, include<stdlib.h> and type system("PAUSE") at the end of your program.

  7. #7
    Unregistered
    Guest
    Code:
    int display (int dia, int mes, int anos) 
    { 
    cout << ""; 
    return 0; 
    }
    You're not displaying anything. You want to cout dia, mes and anos, not "".

  8. #8
    Unregistered
    Guest

    Cool Thanx guys

    Thanx guys for the help. its finanlly running!!

    Thanx a million!!!!
    Taurusborn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM