function or #include problem

i need help when i run this program it has a lot of problems
what i want the program to do is prompt the user to put in two differernt dates and output the number of days in between them.
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <iostream>


using namespace std;

// inputs year and outputs febuary as 1 or 2 to be used in the MonthToDays function
int Febuary(int year)
    {
     
    
    int Divisible_4;
    int Divisible_100;
    int Divisible_400;
    
    
  if((year % 4) == 0)
    {
            Divisible_4 = 1;
    }
    else
    {
            Divisible_4 = 0;
            
    }
     // checkes if years is divisible by 100
    if((year % 100) == 0)
    {
            Divisible_100 = 1;
             
    }
   
    else
    
    {
            Divisible_100 = 0;
            
    }  
     // checkes if years is not divisible by 400
    if((year % 400) == 0 && year >= 400)
    {
      
            Divisible_400 = 1;
             
    }
    else
    {
           
            Divisible_400 = 0;
            
    }
    
    if((Divisible_4 == 1 && Divisible_100 == 0) || (Divisible_100 == 1 && Divisible_400 == 1))
    {
         Febuary = 1;
    }
    else
    {    
         Febuary = 2;
    }
    
    return Febuary;
}
// inputs month and Year and outputs amount of days
int MonthToDays(int Month, int Year)
{
    Febuary(Year);
    int days;
    days = (Month - 1) * 30;
    switch(Month)
    {
                 case Month == 1:
                      days = days + 1
                 case Month == 2:
                      days = days - Febuary + 1
                 case Month == 3:
                      days = days - Febuary + 2
                 case Month == 4:
                      days = days - Febuary + 2
                 case Month == 5:
                      days = days - Febuary + 3
                 case Month == 6:
                      days = days - Febuary + 3
                 case Month == 7:
                      days = days - Febuary + 4
                 case Month == 8:
                      days = days - Febuary + 5
                 case Month == 9:
                      days = days - Febuary + 5
                 case Month == 10:
                      days = days - Febuary + 6
                 case Month == 11:
                      days = days - Febuary + 6
                 case Month == 12:
                      days = days - Febuary + 7
    }
    return days;
}                           
              

int main()
{
    double Day1;
    double Month1;
    double Year1;
    double Day2;           
    double Month2;
    double Year2;
    double TotalDay1; 
    double TotalDay2;
    double EndResult;
    
    char again;
    bool Running = true;
      
    
    cout << " **Welcome to the Date Day Calculator** " << endl;
    
    
    
    while(Running == true)
    {
   
    
    cout << " Type in the year: ";
    cin  >> year;
    
    
               
    
  // user information
    cout << " Plese type in the date in numbers " << endl;
    cout << " make sure you type in the whole year not just the last two digits " << endl;
    cout << " Press enter after each number" << end;
    cout << " this program will caculate the days inbetween two Dates " << end;
    cout << "Date 1: ";
    // input Date 1
    cin  >> Month1;
    cout <<"/";
    cin  >> Day1;
    cout <<"/";
    cin  >> Year1;
    cout << endl;
    cout << "Date 2: ";
    
    TotalDay1 = MonthToDays(Month1, Year1) + Day1 + (Year1 * 365.25);
    cout << "Days: " << TotalDay1 << endl;
    
    // input Date 2
    cin  >> Month2;
    cout <<"/";
    cin  >> Day2;
    cout <<"/";
    cin  >> Year2;
    cout << endl;
    
    TotalDay2 = MonthToDays(Month2, Year2) + Day2 + (Year2 * 365.25);
    cout << "Days: " << TotalDay2 << endl;
    // Displays Days between moths alone with dates
    cout <<" There is " << TotalDay1 - TotalDay2 << " Between " << Month1 << "/" << Day1 << "/" << Year1 << " and "
     << Month2 << "/" << Day2 << "/" << Year2 << endl;
    
    
    
    
    // asks user if they would like to redo program
    cout << " Would You Like To Run this Program Again ( y or n ) " << endl;
    cin  >> again;
    
    
    
    
                 
    
    if(again == 'y' || again == 'Y')
    {
             Running = true;
    }
    else
    {
        if(again == 'n' || again == 'N')
             Running = false;
    }
}
   


    system("PAUSE");
    return 0;
}
          
          
    
                
Last edited on
First of all, your "February" function is kind of like this:

1
2
3
4
5
6
7
8
9
int February(int year) // Signature is OK
{
    if (...) {
        February = 1; // Wrong, you can't assign a value to the function name
    } else {
        February = 2; // Wrong again
    }
    return February; // You must put the value to return here, e.g. a variable or a literal integer
}


You could change that to:
1
2
3
4
5
6
7
8
9
int February(int year)
{
    if (...) {
        return 1; // Return directly when you know the result
    } else {
        return 2; // Same here
    }
    // No need to put a return here, because one of the above will always be taken
}


When you call return, you must assign the result to a variable, like this:
1
2
February(year); // This is not useful
int feb = February(year); // Make "feb" the result of the call 


Finally, when you have variables like "Divisable_4" that is either true or false, you should use bool instead of int, and the keywords true/false instead of 1/0.
I changed it and this is how it looks
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <iostream>


using namespace std;

// inputs year and outputs febuary as 1 or 2 to be used in the MonthToDays function
int FebuaryMonth(int year)
    {
     
    
    bool Divisible_4;
    bool Divisible_100;
    bool Divisible_400;
    
    
  if((year % 4) == 0)
    {
            Divisible_4 = true;
    }
    else
    {
            Divisible_4 = false;
            
    }
     // checkes if years is divisible by 100
    if((year % 100) == 0)
    {
            Divisible_100 = true;
             
    }
   
    else
    
    {
            Divisible_100 = false;
            
    }  
     // checkes if years is not divisible by 400
    if((year % 400) == 0 && year >= 400)
    {
      
            Divisible_400 = true;
             
    }
    else
    {
           
            Divisible_400 = false;
            
    }
    
    if((Divisible_4 == true && Divisible_100 == false) || (Divisible_100 == true && Divisible_400 == false))
    {
         return 1;
    }
    else
    {    
         return 2;
    }
    

}
// inputs month and Year and outputs amount of days
int MonthToDays(int Month, int Year)
{
    int Febuary = FebuaryMonth(Year);
    int days;
    days = (Month - 1) * 30;
    switch(Month)
    {
                 case Month == 1:
                      days = days + 1
                 case Month == 2:
                      days = days - Febuary + 1
                 case Month == 3:
                      days = days - Febuary + 2
                 case Month == 4:
                      days = days - Febuary + 2
                 case Month == 5:
                      days = days - Febuary + 3
                 case Month == 6:
                      days = days - Febuary + 3
                 case Month == 7:
                      days = days - Febuary + 4
                 case Month == 8:
                      days = days - Febuary + 5
                 case Month == 9:
                      days = days - Febuary + 5
                 case Month == 10:
                      days = days - Febuary + 6
                 case Month == 11:
                      days = days - Febuary + 6
                 case Month == 12:
                      days = days - Febuary + 7
    }
    return days;
}                           
              

int main()
{
    double Day1;
    double Month1;
    double Year1;
    double Day2;           
    double Month2;
    double Year2;
    double TotalDay1; 
   
    
    char again;
    bool Running = true;
      
    
    cout << " **Welcome to the Date Day Calculator** " << endl;
    
    
    
    while(Running == true)
    {
   
    
    cout << " Type in the year: ";
    cin  >> year;
    
    
               
    
  // user information
    cout << " Plese type in the date in numbers " << endl;
    cout << " make sure you type in the whole year not just the last two digits " << endl;
    cout << " Press enter after each number" << end;
    cout << " this program will caculate the days inbetween two Dates " << end;
    cout << "Date 1: ";
    // input Date 1
    cin  >> Month1;
    cout <<"/";
    cin  >> Day1;
    cout <<"/";
    cin  >> Year1;
    cout << endl;
    cout << "Date 2: ";
    
    TotalDay1 = MonthToDays(Month1, Year1) + Day1 + (Year1 * 365.25);
    cout << "Days: " << TotalDay1 << endl;
    
    // input Date 2
    cin  >> Month2;
    cout <<"/";
    cin  >> Day2;
    cout <<"/";
    cin  >> Year2;
    cout << endl;
    
    TotalDay2 = MonthToDays(Month2, Year2) + Day2 + (Year2 * 365.25);
    cout << "Days: " << TotalDay2 << endl;
    // Displays Days between moths alone with dates
    cout <<" There is " << TotalDay1 - TotalDay2 << " Between " << Month1 << "/" << Day1 << "/" << Year1 << " and "
     << Month2 << "/" << Day2 << "/" << Year2 << endl;
    
    
    
    
    // asks user if they would like to redo program
    cout << " Would You Like To Run this Program Again ( y or n ) " << endl;
    cin  >> again;
    
    
    
    
                 
    
    if(again == 'y' || again == 'Y')
    {
             Running = true;
    }
    else
    {
        if(again == 'n' || again == 'N')
             Running = false;
    }
}
   


    system("PAUSE");
    return 0;
}
          
          
    
                

but it still dosent work there is a long list of errors
and i was thinking that it might have a library missing from the include directroy because when i click on some of the errors it hilights the include statment
if im not wrong, "system("PAUSE");" needs another library, stdlib.h i think? cant remember.

Anyway, solve your errors top down. solve the 1st one and compile. to your surprise, solving 1 error can solve 100+ of them together. So, do not be daunted by large errors. Only be daunted when you have no errors, yet your program cant run. XD

Double click the error statement, it'll bring u to the line of error.
I haven't actually tried to find your errors, you have to do that yourself, I just try to give you a place to start.

Here's another line that you might want to simplify:
1
2
3
4
5
// When you have boolen values, you don't need to use "== true", and instead
// of "== false", you can use the invertor operator:
if((Divisible_4 == true && Divisible_100 == false) || (Divisible_100 == true && Divisible_400 == false))
// After:
if((Divisible_4 && ! Divisible_100) || (Divisible_100 && ! Divisible_400))
thanks fro the advice i cut down a lot of errors
but i still have long list of errors that when i double click on them they show different codes not any that i wrote there probly the library codes for the editor iam using

well hers the code with all the corrections i made but it still dosent work and the stdlib dosen't solve the problem
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <iostream>



using namespace std;

// inputs year and outputs febuary as 1 or 2 to be used in the MonthToDays function
int FebuaryMonth(int year)
    {
     
    
    bool Divisible_4;
    bool Divisible_100;
    bool Divisible_400;
    
    
  if((year % 4) == 0)
    {
            Divisible_4 = true;
    }
    else
    {
            Divisible_4 = false;
            
    }
     // checkes if years is divisible by 100
    if((year % 100) == 0)
    {
            Divisible_100 = true;
             
    }
   
    else
    
    {
            Divisible_100 = false;
            
    }  
     // checkes if years is not divisible by 400
    if((year % 400) == 0 && year >= 400)
    {
      
            Divisible_400 = true;
             
    }
    else
    {
           
            Divisible_400 = false;
            
    }
    
    if((Divisible_4 == true && Divisible_100 == false) || (Divisible_100 == true && Divisible_400 == false))
    {
         return 1;
    }
    else
    {    
         return 2;
    }
    

}
// inputs month and Year and outputs amount of days
int MonthToDays(int Month, int Year)
{
    int Febuary = FebuaryMonth(Year);
    int days;
    Month = Month - 1;
    switch(Month)
    {
                 case 1:
                      days = (days + 1) * 30;
                      break;
                 case 2:
                      days = (days - Febuary + 1) * 30;
                      break;
                 case 3:
                      days = (days - Febuary + 2) * 30;
                      break;
                 case 4:
                      days = (days - Febuary + 2) * 30;
                      break;
                 case 5:
                      days = (days - Febuary + 3) * 30;
                      break;
                 case 6:
                      days = (days - Febuary + 3) * 30;
                      break;
                 case 7:
                      days = (days - Febuary + 4) * 30;
                      break;
                 case 8:
                      days = (days - Febuary + 5) * 30;
                      break;
                 case 9:
                      days = (days - Febuary + 5) * 30;
                      break;
                 case 10:
                      days = (days - Febuary + 6) * 30;
                      break;
                 case 11:
                      days = (days - Febuary + 6) * 30;
                      break;
                 case 12:
                      days = (days - Febuary + 7) * 30;
                      break;
                 default:
                         cout << " You Have typed a invalid month" << endl;
    }
    return days;
}                           
              

int main()
{
    int Day1;
    int Month1;
    int Year1;
    int Day2;           
    int Month2;
    int Year2;
    double TotalDay1; 
    double TotalDay2;
   
    
    char again;
    bool Running = true;
      
    
    cout << " **Welcome to the Date Day Calculator** " << endl;
    
    
    
    while(Running == true)
    {
   
    
    
    
    
               
    
  // user information
    cout << " Plese type in the date in numbers " << endl;
    cout << " make sure you type in the whole year not just the last two digits " << endl;
    cout << " Press enter after each number" << endl;
    cout << " this program will caculate the days inbetween two Dates " << endl;
    cout << "Date 1: ";
    // input Date 1
    cin  >> Month1;
    cout <<"/";
    cin  >> Day1;
    cout <<"/" << endl;
    cin  >> Year1;
    
    cout << "Date 2: ";
    
    TotalDay1 = MonthToDays(Month1, Year1) + Day1 + (Year1 * 365.25);
    cout << "Days: " << TotalDay1 << endl;
    
    // input Date 2
    cin  >> Month2;
    cout <<"/";
    cin  >> Day2;
    cout <<"/" << endl;
    cin  >> Year2;
    
    
    TotalDay2 = MonthToDays(Month2, Year2) + Day2 + (Year2 * 365.25);
    cout << "Days: " << TotalDay2 << endl;
    // Displays Days between moths alone with dates
    cout <<" There is " << TotalDay1 - TotalDay2 << " Between " << Month1 << "/" << Day1 << "/" << Year1 << " and "
     << Month2 << "/" << Day2 << "/" << Year2 << endl;
    
    
    
    
    // asks user if they would like to redo program
    cout << " Would You Like To Run this Program Again ( y or n ) " << endl;
    cin  >> again;
    
    
    
    
                 
    
    if(again == 'y' || again == 'Y')
    {
             Running = true;
    }
    else
    {
        if(again == 'n' || again == 'N')
             Running = false;
    }
}
   


    system("PAUSE");
    return 0;
}
          
          
    
                

how does the inventor operation work
Last edited on
>> how does the inventor operation work

If b is a bool variable:
 
! b

is the same as
 
b == false
could i use it hear as well or does it only work in if statements
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
if((year % 100) == 0)
    {
            Divisible_100 = true;
             
    }
   
    else
    
    {
            Divisible_100 = false;
            
    }  
     // checks if years is not divisible by 400
    if((year % 400) == 0 && year >= 400)
    {
      
            Divisible_400 = true;
             
    }
    else
    {
           
            Divisible_400 = false;
            
    }

Last edited on
It works for comparicon (==). Assignment (=) is something completely different.
Topic archived. No new replies allowed.