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
How to add an image/C++ OpenGL?
Hi,
I have been trying to look online for this and, so far, I haven't found anything usef
Comment Mod System Effects all rows...
Sorry if its confusing but here is whats going on: I have a table in a database called comments and
i have no idea why this isn't working
Code: <?php
session_start();
include("connect.php");
error_reporting(E
Stuck with preg_replace
Hi,
I'm trying to use preg_replace to remove part of the IP address submitted using a form on
pagination numbering pattern
Hello,
I have following code which works great for pagination. but i have small issue now.
PHP & Java
Hello,
can PHP code be used inside java code?
Code: <SCRIPT LANGUAGE="Java
System copy error in RUN ABAP REPORT PHASE
Hi,
I am performing system copy on my test server. I have previously taken export of JAVA + A
very easy question about SQL info
Hello,
I think that I have a very easy question.
I know how to create a form using php SQL and
why isn't this PHP code working ???
it's suppose to find a name on the database.
<?php
$s = $_POST["lname&
Querying info from one table based on info in another
Hi, I am currently trying to make a part for my user driven website where one user can subscribe to