Thread: calling up a function twice

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    30

    calling up a function twice

    HEllo, I need to call a function up twice withing another function. My problem is the fact that the second itme I call it up it overwrites the first one. Here is what I have for the code (getYear() is the function I am calling up):

    void doYearRange()
    {
    int dys=0;
    int yr;
    int yr1;
    int yr2;
    yr1 = getYear();
    yr2 = getYear();
    for (yr =yr1; yr<=yr2; yr++)

    if (isLeapYear(yr) ==true)
    {
    std::cout<<yr<<endl;
    dys +=366;
    }
    else dys +=365;

    std::cout<<dys<<" days between "<<yr1<<" and "<<yr2<<endl;
    }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    >yr1 = getYear();
    >yr2 = getYear();

    Can you explain your problem more closely ?
    As I see it, you should get two years, yr1 and 2,
    whose value depends entirely on the result of the
    function. If the function manages to generate two
    different years without parameters ( i.e. by user-input )
    you should end up with two different values in yr1 and 2.

    Maybe you can post the getYear() function ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    Here is my getYear() function:
    int getYear()
    {
    int yr;
    while (yr <= 1582 || yr >= 4000)
    {
    std::cout<<"Enter in a year between and not including 1582 and $
    std::cin>>yr;
    }
    return yr;
    }

  4. #4
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    that wuold help!

    it would help, if we what getyear() does

    possibilitie are receives "input" or "generate input"(randon)
    Ünicode¬>world = 10.0£

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    getYear() prompts the user for a year. Then the user inputs a year.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    Initialize the yr variable first. if you don't do that then, when the condition statement in the while loop is evaluated, the result can not be predicted.

    e.g.
    int yr = 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 05:32 PM