# calling up a function twice

• 10-10-2001
simhap
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;
}
• 10-10-2001
nvoigt
>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 ?
• 10-10-2001
simhap
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;
}
• 10-10-2001
bljonk
that wuold help!
:confused: it would help, if we what getyear() does

possibilitie are receives "input" or "generate input"(randon)
• 10-10-2001
simhap
getYear() prompts the user for a year. Then the user inputs a year.
• 10-10-2001
damyan
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;