function not returning the correct value


Posted on 16th Feb 2014 07:03 pm by admin

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include 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 Like 44 Dislike
Previous forums Next forums
Other forums

What are causes of a connection-timeout with fopen()?
Hello! Here is the situation: The server I host my website on just upgraded it's PHP build from 4.4.

Floating Point Precision Loss
I'm writing a program to draw a three-dimensional cube (with a corner cut off) without using any 3D

mails going in spam??
The mails I sent to folks in my database using mail(function) are going in spam??

Any idea ho

include problem
I have my root folder as:
Code: $root = $_SERVER["SITE_HTMLROOT"]; // the server root<

Pls help with PHP
Pls can anyone direct me on how to create a user account for a customer. For example i want know if

PHP onsubmit in the form not going to the fuction.
I have a form through ‘onsubmit’ calling a function validation(). But not going to the

mail with attachment problems
Hi. I have the following code:
Code: else if(file_exists("site".$timp.".zip")

Creation of Raw Exposure manually
SAP Gurus

I am creating Raw Exposure ( Hedge management ) thru T Code TEM10 with followin

Apple's revamped lineup arrives

I'm personally curious about the magic mouse.. a multi-touch concept sounds like it could be nea

Is there a function ... auto send IP
Is there some function that can be sent to a ddns service that returns the ip address of a ddns forw

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash