Problem with dates and years

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
/*

Write a program that checks the validity of a date. The date is entered as separate numbers for 
the month, day and year. 
For example, if the date was March 16th, 2008, the user would enter 3 followed by 16 followed 
by 2008. The program checks that: 

• the month is a valid number for a month 

• the number of days in the month is valid for that month. 

• If the user entered February 29th

, you must check if the the year is a valid leap year.
The program just outputs the date and tells the user if the date is valid or not. 
The program contains four functions:

• The main function.

• A function that gives instructions to the user about how to enter the date 

• A function that is sent a month and a day and returns a Boolean value to represent 
whether that is a valid day for that month. This function should use a switch statement.

• The leap year function that determines if this is a leap year. This is  your leap year 
function from last week.
*/

#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

// declaring
int Day = 0;
int Month = 0;
int Year = 0;
bool leapYear (int);


int main(int argc, char *argv[])
{
    // outputting messages to the user
    cout << "Lets check your dates shall we?" << endl;
    cout << "Please enter in a two(2) digit number for the month." << endl;
    cin >> Month;
    cout << "Please enter in a two(2) digit number for the day." << endl;
    cin >> Day;
    cout << "Please enter in a four(4) digit number for the year." << endl;
    cin >> Year;
    
    
    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

switch(Month)
{
       case 01:
            if (Day == 1 ... 31)
               cout << "January" << Day << "th," << Year << "," << endl;
            break;
       case 02:
            if (Day == 1 ... 28)
               cout << "February" << Day << "th," << Year << "," << endl;
            else if (Day == 29)
               leapYear(Day);  
            break;
       case 03:
            if (Day == 1 ... 31)
               cout << "March" << Day << "th," << Year << "," << endl;
            break;
       case 04:
            if (Day == 1 ... 30)
               cout << "April" << Day << "th," << Year << "," << endl;
            break;
       case 05:
            if (Day == 1 ... 31)
               cout << "May" << Day << "th," << Year << "," << endl;
            break;
       case 06:
            if (Day == 1 ... 30)
               cout << "June" << Day << "th," << Year << "," << endl;
            break;
       case 07:
            if (Day == 1 ... 31)
               cout << "July" << Day << "th," << Year << "," << endl;
            break;
       case 08:
            if (Day == 1 ... 31)
               cout << "August" << Day << "th," << Year << "," << endl;
            break;
       case 09:
            if (Day == 1 ... 30)
               cout << "September" << Day << "th," << Year << "," << endl;
            break;
       case 10:
            if (Day == 1 ... 31)
               cout << "October" << Day << "th," << Year << "," << endl;
            break;
       case 11:
            if (Day == 1 ... 30)
               cout << "November" << Day << "th," << Year << "," << endl;
            break;
       case 12:
            if (Day == 1 ... 31)
               cout << "December" << Day << "th," << Year << "," << endl;
            break;
}


// leap year bool
bool leapYear (int)
{
    if ((( Year % 4 == 0) && (! ( Year % 100 == 0))) || (( Year % 4 == 0) && (! ( Year % 100 == 0))&&( Year % 400 == 0))) 
     return true;
      
    else
        return false;
        }




61 expected unqualified-id before "switch"
61 expected `,' or `;' before "switch"

93:13 invalid digit "8" in octal constant
97:13invalid digit "9" in octal constant

also what else would i have to add to where?
please help

edit : updated code
Last edited on
1
2
3
4
} // this curly brace end the main function should move below

switch(Month)
{


In C,C++, when you put 08 it interpret as octal number, 0x8 it interpret as hexadecimal number so for your case you just put 8,9,10 etc.

Also does C/C++ support syntax like 1...31 ? Usually we write as if (Day>=1 && Day<=31)
thank you!

now i edited the code to this... and still getting a 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
/*

Write a program that checks the validity of a date. The date is entered as separate numbers for 
the month, day and year. 
For example, if the date was March 16th, 2008, the user would enter 3 followed by 16 followed 
by 2008. The program checks that: 

• the month is a valid number for a month 

• the number of days in the month is valid for that month. 

• If the user entered February 29th

, you must check if the the year is a valid leap year.
The program just outputs the date and tells the user if the date is valid or not. 
The program contains four functions:

• The main function.

• A function that gives instructions to the user about how to enter the date 

• A function that is sent a month and a day and returns a Boolean value to represent 
whether that is a valid day for that month. This function should use a switch statement.

• The leap year function that determines if this is a leap year. This is  your leap year 
function from last week.
*/

#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

// declaring
int Day = 0;
int Month = 0;
int Year = 0;
bool leapYear (int);


int main(int argc, char *argv[])
{
    // outputting messages to the user
    cout << "Lets check your dates shall we?" << endl;
    cout << "Please enter in a two(2) digit number for the month." << endl;
    cin >> Month;
    cout << "Please enter a number for the day (1 - 12)." << endl;
    cin >> Day;
    cout << "Please enter in a four(4) digit number for the year." << endl;
    cin >> Year;
    
    
    switch(Month)
{
       case 1:
            if (Day>=1 && Day<=31)
               cout << "January" << Day << "th," << Year << "," << endl;
            break;
       case 2:
            if (Day>=1 && Day<=28)
               cout << "February" << Day << "th," << Year << "," << endl;
            else if (Day == 29)
               leapYear(Year)  
               cout << "February" << Day << "th," << Year << "," << "Is also a leap year!" endl;
               else
               cout << "Invalid date." << endl;
            break;
       case 3:
            if (Day>=1 && Day<=31)
               cout << "March" << Day << "th," << Year << "," << endl;
            break;
       case 4:
            if (Day>=1 && Day<=30)
               cout << "April" << Day << "th," << Year << "," << endl;
            break;
       case 5:
            if (Day>=1 && Day<=31)
               cout << "May" << Day << "th," << Year << "," << endl;
            break;
       case 6:
            if (Day>=1 && Day<=30)
               cout << "June" << Day << "th," << Year << "," << endl;
            break;
       case 7:
            if (Day>=1 && Day<=31)
               cout << "July" << Day << "th," << Year << "," << endl;
            break;
       case 8:
            if (Day>=1 && Day<=31)
               cout << "August" << Day << "th," << Year << "," << endl;
            break;
       case 9:
            if (Day>=1 && Day<=30)
               cout << "September" << Day << "th," << Year << "," << endl;
            break;
       case 10:
            if (Day>=1 && Day<=31)
               cout << "October" << Day << "th," << Year << "," << endl;
            break;
       case 11:
            if (Day>=1 && Day<=30)
               cout << "November" << Day << "th," << Year << "," << endl;
            break;
       case 12:
            if (Day>=1 && Day<=31)
               cout << "December" << Day << "th," << Year << "," << endl;
            break;
       default:
               cout << "Invalid date." << endl;
               break;
}

    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}



// leap year bool
bool leapYear (int)
{
    if ((( Year % 4 == 0) && (! ( Year % 100 == 0))) || (( Year % 4 == 0) && (! ( Year % 100 == 0))&&( Year % 400 == 0))) 
     return true;
      
    else
        return false;
        }



65 expected `;' before "cout"
Last edited on
1
2
3
4
5
6
7
8
9
            else if (Day == 29) { // put this curly brace
               leapYear(Year)  
               cout << "February" << Day << "th," << Year << "," << "Is also a leap year!" << endl;//add one more <<

            } //put this curly brace

               else
               cout << "Invalid date." << endl;
            break;
along with sohguanh suggestion put ; on line 64
 
leapYear(Year);
now im getting
66 expected primary-expression before "else"
With Some modification :

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
#include <cstdlib>
#include <iostream>
#include <cmath>

	#define stringify(mymonths ) # mymonths

using namespace std;

// declaring
int Day = 0;
int Month = 0;
int Year = 0;
bool leapYear (int);

enum month { January = 1 , Feb  ,March , Aprial , May , June , July , Agust , Sept , Oct , Nov , Dec } ;
const char* m_month[] = 
{
	stringify(January),
	stringify(Feb),
	stringify(March),
	stringify(Aprial)

	stringify(May),
	stringify(June),
	stringify(July),
	stringify(Agust)
			stringify(Sept),
	stringify(Oct),
	stringify(Nov),
	stringify(Dec)


};

int main(int argc, char *argv[])
{
	// outputting messages to the user
	cout << "Lets check your dates shall we?" << endl;
	cout << "Please enter in a two(2) digit number for the month." << endl;
	cin >> Month;
	cout << "Please enter in a two(2) digit number for the day." << endl;
	cin >> Day;
	cout << "Please enter in a four(4) digit number for the year." << endl;
	cin >> Year;

    
    
    
    
	system("PAUSE");
	return EXIT_SUCCESS;
}

switch( Month )
{
       case 01:
		   case  03 : 
		   case 05:
		   case  07 : 
		   case 08:
		   case  10 : 
		   case  12 : 
                 cout <<m_month[Month] << Day << "th," << Year << "," << endl;
            break;
       case 02:
       case 04:
       case 06:
       case 09:
       case 11:
               cout <<<m_month[Month] << Day << "th," << Year << "," << endl;
            break;
}


// leap year bool
bool leapYear (int)
{
    if ((( Year % 4 == 0) && (! ( Year % 100 == 0))) || (( Year % 4 == 0) && (! ( Year % 100 == 0))&&( Year % 400 == 0))) 
     return true;
      
    else
        return false;
        }

Topic archived. No new replies allowed.