I have a program that needs to return a value from a function. I have an output statement inside the function just to see what the output is, and it sems to work. However, upon returning the function value, it seems to always return false. It is a Boolean function. Can someone at least point me out to where I might look to understand what I am doing wrong?
using namespace std;
bool leap(int testYear);
int dayNumber(int testMonth, int testDay, bool isLeapyear);
int year, totalDay, month;
bool isLeap;
int main()// start of main function
{
int day, x, dayofYear;
//Begin loop to input month, day, year. Test for validity.
for (x = 1; x <= 1; x = x + 1)
{
cout << "Please input the month number in 2 digits : ";
cin >> month;
if (1 > month || month > 12)
{ cout << "nYou hve entered an incorrect month numbern"; break;}
cout << "nPlease input the day of the month in 2 digits : ";
cin >> day;
if (1 > day || day > 31)
{ cout << "nYou hve entered an incorrect day numbern"; break;}
cout << "nPlease input the YEAR in 4 digits : ";
cin >> year;
} //End input loop
//Invoke leap year function
bool leapYear = leap (year);
cout << "nn" << isLeap << "nn";
//Invoke day of year function
dayofYear = dayNumber (month, day, isLeap);
//Output results of the functions
cout << " the day number for " << month << "/" << day << "/" << year;
cout << " is " << dayofYear << "nn";
//Output programmer ID
system ("pause");
return 0;// Exit the main function
}
//Begin LeapYear calculate function
bool leap( int testYear)
{
bool isLeap = (testYear % 4 == 0) && (testYear % 100 == 0) || (testYear % 400 == 0);
cout << "n" << isLeap << "n";
return isLeap;
}//End LeapYear
//Begin day calculate function
int dayNumber(int testMonth, int testDay, bool isLeapyear)
{
totalDay = testDay;
if (testMonth >= 2)
switch (isLeap)
{
case 0: totalDay = totalDay + 28;
break;
case 1: totalDay = totalDay + 29;
}
if (testMonth >= 3) totalDay = totalDay + 31;
if (testMonth >= 4) totalDay = totalDay + 30;
if (testMonth >= 5) totalDay = totalDay + 31;
if (testMonth >= 6) totalDay = totalDay + 30;
if (testMonth >= 7) totalDay = totalDay + 31;
if (testMonth >= 8) totalDay = totalDay + 31;
if (testMonth >= 9) totalDay = totalDay + 30;
if (testMonth >= 10) totalDay = totalDay + 31;
if (testMonth >= 11) totalDay = totalDay + 30;
if (testMonth >= 12) totalDay = totalDay + 31;
return totalDay;
}//End day
I would appreciate it very much.
No comments posted yet
Your Answer:
Login to answer
57 44
Other forums
Get word number x from string?
How can I use a function to loop through a string, and "have a look at" every word in the
Why do I get this error
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/a5488351/public_html/b
Linkage between two scripts
Okay say I have this for a link in a script:
Code: <li><a href="#&q
disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte
insert/update functions for mysql, what do you think?
I am working on two really simple functions that automatically generate (and execute) insert and upd
downloading a file as HTML
Hi.
I'm rather confused with forcing a download. I just want to save dynamic content (from $_SESS
How to secure my login data to my database?
Hi there,
It may be a stupid question but I don't know how to secure my login data to my data
can i optmize image to 50% quality before uploading 2 server
Hi there
i have jus written a php program to upload and display images but when i try to uplo
Multiple websites question.
Hi, does php have any functionality that enables a programmer to extract information from a website
php slowing my site?
Hi all,
I think that one of the reasons that my site doesn't work fast is that the code is ve