Basic Function problem

This is a discussion on Basic Function problem within the C++ Programming forums, part of the General Programming Boards category; Ok, I'm writing a program that reads the age from someone and decides if they're old enough to receive social ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    4

    Angry Basic Function problem

    Ok, I'm writing a program that reads the age from someone and decides if they're old enough to receive social security, i HAVE to use 2 functions, one for the age and one to do the computation and display. THe program on below looks correct for me but when i execute nothing pops up on the screen, BTW im using VC++ 6 so all i see is the black screen with "press any key to continue" i'm so frustrated and can't move on if i dont figure this thing out, thanks allot...sorry if the code is a mess but i don't know how to use that thing yet to put code on it

    #include <iostream.h>


    int promptAge();
    void socialAge(int);

    int main()

    {
    int age;

    int promptAge();

    void socialAge(int age);

    return 0;

    }

    //************************************************** *
    int promptAge()

    {
    int age;

    cout << "Please enter your age to decide if you are eligible for SS " << endl ;
    cin >> age;

    return age;
    }

    /************************************************** *
    void socialAge(int age)

    {

    if(age >= 62)
    cout << "You are old enough to receive SS";


    else
    cout << "Your are not old enough to receive SS";

    }

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    /* maybe this will help!
    */

    #include <iostream.h>
    #include <stdlib.h>


    void socialAge(int age)

    {

    if(age >= 62)
    cout << "You are old enough to receive SS";


    else
    cout << "Your are not old enough to receive SS";

    }
    main()
    {
    int mainage; //so u know which age!
    cout<<"how old are you?\n"; //question!
    cin>>mainage; //give it a value!
    socialAge(mainage); //put the mainage in the function!
    system ("pause");
    return 0; //ok!
    }

  3. #3
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Its probably because you are only redefining the functions in main, not calling them.

    Code:
    int age;
    
    int promptAge(); 
    
    void socialAge(int age);
    Should be

    Code:
    int mainage;
    
    promptAge(); 
    
    socialAge(mainage);

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    what is the promtAge for?

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    4
    i was just writing a little program from a text book and it required us to use functions to accomplish the task, so i made promptAGE the function to ask for the age and save it to "int age; "

    OH yeah, thanks allot for your help guys i didn't expect an answer this quick, i really appreciate your help, i'll be coming here more often!!

    Pode, i just have a question why did you use system ("pause");

    i've never seen this command?
    Last edited by KuriusT; 04-10-2002 at 02:07 PM.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    using dev-c++ wont pause by itself thats why i used it .
    if i didnt i would't even get to see what the answer was cause
    the window just pops up for one second and then it disappears

    btw did u solve the problem?

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    4
    yeah i solved the problem lol all i had to do was to remove the the type from main because they other guy was right, it was as if i was giving the function prototype again in main, so yeah it worked oh yeah i started to use debugger yesterday pretty cool tool, the only thing though, when it traces a cout statement for example it goes into the the class definition of cout and all the other operators....why does it do this?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. DLL Function / Load Library Problem
    By cboard_member in forum Windows Programming
    Replies: 5
    Last Post: 12-10-2005, 09:11 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  4. Replies: 5
    Last Post: 02-08-2003, 06:42 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM

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