please fix it for me guys!

I`m really confiused about it pleas help me. I`m a beginner. this program supposed to show your age, by day/week/year. Also the day of the week that u borne.
It shouldn`t work after 150 year. people less than 10 years old and above 100 years are not allow to use it.
what for compiler should I use? I used Devc++ but after upgrading my windows to win10 it`s not work anymore

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
  // progeraam opgaven1
#include <iostream>
#include <string>
#include <string>
using namespace std;

const int currentyear = 2015;

int GetDates(int year, int month, int day);  //Functionprototype.
int JulianDateNum(int day,int jdn,long intRes1,long intRes2,long intRes3);
int main()
{
    int year;                                              //Declare variables
    int month;
    int day;
    int dayOfWeek;
    int jdn;
    cout << "This progeram was created to find the Birth day and you age "
         << "created by ....." << endl;
    //Get input from user
     cout << "In wich year did u borned? (yyyy): ";  
     cin >> year;
     //pprogeram should work for 150 years  
     if (currentyear - year < 0 || currentyear - year > 150) {           
        cout << "This year is out of range! Please enter a year " << endl;
        return 1;
       } 
          // check if user abvoe 10 and under 150 year is
     if (currentyear - year < 10){
        cout << "This progeram is not for you" << endl;
        return 1;
       }
     if (currentyear - year > 100){
        cout << "your are too old for this progeram" << endl;
        return 1;
       }
     //Get the mothn and check it for condition                            
     cout << "in which month did you bornd(1-12)? (mm)"  << endl; 
     cin >> month;  
     if (month < 1 || month > 12) {
         cout << "Invalid data! Please enter a month " << endl;
         return 1;
        }
     if (currentyear - year == 10 && currentmonth - month < 0){
         cout << "Come back next year" << endl;
         retrun 1;
        } 
     if (currentyear - year == 10 && currentmonth - month > 0){
         cout << "Lets sleep,you are too old" << endl;
         return 1;
        }
        // Get Bday and check it for condition                 
     cout << "In wich day did you borned? day (dd): ";   
     cin >> day; 
     if ( day < 1 || day > 31){
        cout << "Lets check the day agin" << endl;
        returne 1;
       }   
     switch (month){
            case 1: 
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
               if ( day > 31){
                  cout << "It is not a  jok!,bye" << endl;
                  return 1;
                 }
                break;
           case 2:
               if (year % 4 == 0){
                 if (day > 20 ){ 
                  cout << "It is not a  jok!,bye" << endl;
                  return 1;
                    }      
                 }
               else{
                    if ( day > 28){
                      cout << "It is not a  jok!,bye" << endl;
                      return 1;
                      }
                 }  
               break;
           case 4:
           case 6:
           case 9:
           case 11:
                if (day > 30){
                   cout << "It is not a jok!, bye" << endl;
                   retrun 1;
                 }
               break;
          if (currentyear - year == 10 && currentmonth - month == 0 &&
          currentday - day < 0){
         cout << "wait" << day - currentday << "days and try again" << endl;
         return 0;
       }
     if (currentyear - year == 100 && currentmonth - month == 0 
         && currentday - day < 0){
         cout << "you just pased the border for progeram " << endl;
         return 1;
       }
       //days between 1-1-1901 and Bdate
       
        difference = ( year - 1901) / 4 + Byear + Bday + mshift;                                  // calculates day of the week
     days = day - 1;
     if (month > 1){
         days = days + 31;
         }
     if (month > 2){
         days = days + 28;
         }               
     if (month > 3){
         days = days + 31;
         }          
     if (month > 4){
         days = days + 30;
         }        
     if (month > 5){
         days = days + 31;
         }    
     if (month > 6){
         days = days + 30;
         }    
     if (month > 7){
         days = days + 31;
         }    
     if (month > 8){
         days = days + 31;
         }    
     if (month > 9){
         days = days + 30;
         }    
     if (month > 10){
         days = days + 31;
         }
     if (month > 11){
         days = days + 30;
         }
     // calculate days
     days = days + (( year - 1901) * 365) + ((year - 1900) / 4));
     //calculate months
     week = ((1 + days) % 7) + 1;
     cout << "Untill today you lived for :" << days << endl;
     cout << "Untill today you lived for :" << weeks << endl;
     //day of week
     if (dayOfWeek == 0){
            cout << "The day of your Birth is : Mo" << endl;
            break;
            return 0;
            } 
        else if (dayOfWeek == 1){
            cout << "The day of your Birth is :Tu" << endl;
            break;
            return 0;
            }
        else if (dayOfWeek == 2){
            cout << "The day of your Birth is :We" << endl;
            break;
            return 0;
            }
        else if (dayOfWeek == 3){
            cout << "The day of your Birth is :Th" << endl;
            break;
            return 0;
            } 
        else if (dayOfWeek == 4){
            cout << "The day of your Birth is :Fr" << endl;
            break;
            return 0;
            } 
        else if (dayOfWeek == 5){
            cout << "Sa" << endl;
            break;
            return 0;
            } 
        else if (dayOfWeek == 6){
            cout << "Su" << endl;
        break;
            return 0;
            } 
   return 0;                           // Terminates program.                     
}
Last edited on
retunr ? returne ? defult ? urrentyear ?
yes, if the conditions is not right then the program should stopt. that`s why. is that wong?
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/windows/174490/
closed account (48T7M4Gy)
For free compilers, use Codeblocks or Visual Studio Community.

Also note that you have to spell the C++ words exactly, like return, default
yes, I did it, but still not working?
closed account (48T7M4Gy)
 In function 'int main()':
44:38: error: 'currentmonth' was not declared in this scope
46:10: error: 'retrun' was not declared in this scope
48:38: error: 'currentmonth' was not declared in this scope
57:9: error: 'returne' was not declared in this scope
92:20: error: 'retrun' was not declared in this scope
95:43: error: 'currentmonth' was not declared in this scope
96:11: error: 'currentday' was not declared in this scope
100:39: error: 'currentmonth' was not declared in this scope
101:13: error: 'currentday' was not declared in this scope
107:9: error: 'difference' was not declared in this scope
107:43: error: 'Byear' was not declared in this scope
107:51: error: 'Bday' was not declared in this scope
107:58: error: 'mshift' was not declared in this scope
108:6: error: 'days' was not declared in this scope
145:6: error: 'week' was not declared in this scope
147:48: error: 'weeks' was not declared in this scope
17:9: warning: unused variable 'jdn' [-Wunused-variable]
185:1: error: expected '}' at end of input
 


OK you have all these errors to fix. They are why it won't run. Start at the first error at the top of the list, fix it, run again, get the error list from that run and repeat.

All the best. If you have any problems let us know. We help but generally don't fix without you trying first.

Cheers.
Last edited on
This is acully my question , I have no source code for current date. how should I declare it?
closed account (48T7M4Gy)
The error list says at line 44 you haven't declared a variable called current month. All you have to do is declare it yaser. You did it with other variables ...
Last edited on
You can grab the current unix timestamp from time(0); in the <time.h> header

If you want to pull out the current date, you can use the localtime() function such as this function to get a month from a timestamp (which you receive from the time(0) function)

1
2
3
4
5
6
7
int getMonth(time_t timeval){
 struct tm * timeinfo;
 timeinfo = localtime(&timeval);
 if (timeinfo!=NULL)
    return timeinfo->tm_mon + 1;
 return -1;
}
@kemort : I need a current date source to declare currentday, currentmonth and currentyear and I don`t have it, I try several codes but no success. I shouldn`t ask it from user.

@wizebin: if I use this codes how can I find currentdate? its only for time!
closed account (48T7M4Gy)
currentyear is at line 7
Last edited on
I have this but ther is a problem that I don`t know what that is?
[.code]

tm s;
time-t(t);
time (&t);
s= * localtime (&t);
day = s.tm_mon + 1;
month = s.tm_year
year+ s.tm- year
srand (time(zero))
[./code]
closed account (48T7M4Gy)
wizebin above has shown you how to get the system time

You can also check the online tutorial here. just search time.

Maybe the GetDates function you wrote does what you want.
Last edited on
I made some changes on it but stil I have problem with current dates :(( help me
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
// progeraam opgaven1
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
const int currentyear = 2015;

int GetDates(int year, int month, int day);  //Functionprototype.
    int year;                                              //Declare variables
    int month;
    int day;
    int dayOfWeek;
    int jdn;
    int currentday;
    int currentmonth;
    int currentyear;
    int difference
    // current date
    tm s;
    time_t t;
    time (&t);
    s = * localtime (&t);
    currentday = s.tm_mday;
    currentmonth = s.tm_mon + 1;
    currentyear = s.tm_year + 1900;
    cout << "This progeram was created to find the Birth day and you age "
         << "created by Yaser kazemi (s1714341)" << endl;
    //Get input from user
     cout << "In wich year did u borned? (yyyy): ";  
     cin >> year;
     //pprogeram should work for 150 years  
     if (currentyear - year < 0 || currentyear - year > 150) {           
        cout << "This year is out of range! Please enter a year " << endl;
        return 1;
       } 
          // check if user abvoe 10 and under 150 year is
     if (currentyear - year < 10){
        cout << "This progeram is not for you" << endl;
        return 1;
       }
     if (currentyear - year > 100){
        cout << "your are too old for this progeram" << endl;
        return 1;
       }
     //Get the mothn and check it for condition                            
     cout << "in which month did you bornd(1-12)? (mm)"  << endl; 
     cin >> month;  
     if (month < 1 || month > 12) {
         cout << "Invalid data! Please enter a month " << endl;
         return 1;
        }
     if (currentyear - year == 10 && currentmonth - month < 0){
         cout << "Come back next year" << endl;
         return 1;
        } 
     if (currentyear - year == 10 && currentmonth - month > 0){
         cout << "Lets sleep,you are too old" << endl;
         return 1;
        }
        // Get Bday and check it for condition                 
     cout << "In wich day did you borned? day (dd): ";   
     cin >> day; 
     if ( day < 1 || day > 31){
        cout << "Lets check the day agin" << endl;
        return 1;
       }   
     switch (month){
            case 1: 
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
               if ( day > 31){
                  cout << "It is not a  jok!,bye" << endl;
                  return 1;
                 }
                break;
           case 2:
               if (year % 4 == 0){
                 if (day > 20 ){ 
                  cout << "It is not a  jok!,bye" << endl;
                  return 1;
                    }      
                 }
               else{
                    if ( day > 28){
                      cout << "It is not a  jok!,bye" << endl;
                      return 1;
                      }
                 }  
               break;
           case 4:
           case 6:
           case 9:
           case 11:
                if (day > 30){
                   cout << "It is not a jok!, bye" << endl;
                   return 1;
                 }
               break;
               }
     if (currentyear - year == 10 && currentmonth - month == 0 &&
          currentday - day < 0){
         cout << "wait" << day - currentday << "days and try again" << endl;
         return 0;
       }
     if (currentyear - year == 100 && currentmonth - month == 0 
         && currentday - day < 0){
         cout << "you just pased the border for progeram " << endl;
         return 1;
       }
       //days between 1-1-1901 and Bdate
       
        difference = ( year - 1901) / 4 + year + day + mshift;                                  // calculates day of the week
     day = day - 1;
     if (month > 1){
         day = day + 31;
         }
     if (month > 2){
         day = day + 28;
         }               
     if (month > 3){
         day = day + 31;
         }          
     if (month > 4){
         day = day + 30;
         }        
     if (month > 5){
         day = day + 31;
         }    
     if (month > 6){
         day = day + 30;
         }    
     if (month > 7){
         day = day + 31;
         }    
     if (month > 8){
         day = day + 31;
         }    
     if (month > 9){
         day = day + 30;
         }    
     if (month > 10){
         day = day + 31;
         }
     if (month > 11){
         day = day + 30;
         }
     // calculate days
     day = day + (( year - 1901) * 365) + ((year - 1900) / 4));
     //calculate months
     week = ((1 + day) % 7) + 1;
     cout << "Untill today you lived for :" << day << endl;
     cout << "Untill today you lived for :" << week << endl;
     //day of week
     if (dayOfWeek == 0){
            cout << "The day of your Birth is : Mo" << endl;
            return 0;
            } 
        else if (dayOfWeek == 1){
            cout << "The day of your Birth is :Tu" << endl;
            return 0;
            }
        else if (dayOfWeek == 2){
            cout << "The day of your Birth is :We" << endl;
            return 0;
            }
        else if (dayOfWeek == 3){
            cout << "The day of your Birth is :Th" << endl;
            return 0;
            } 
        else if (dayOfWeek == 4){
            cout << "The day of your Birth is :Fr" << endl;
            return 0;
            } 
        else if (dayOfWeek == 5){
            cout << "Sa" << endl;
            return 0;
            } 
        else if (dayOfWeek == 6){
            cout << "Su" << endl;
            return 0;
            } 
   return 0;                                           
}
Last edited on
I'm a beginner too but noticed some obvious errors.

missing a semicolon(;) on line 20.
declared a const int on line 9 (currentyear) and then you've tried to assign a different value to it in line 19.
mshift is undefined at 119
week is undefined at 157

Hope it helps
Topic archived. No new replies allowed.