Need help with a program plz

Hi i need help, this program meant to take date by integer numbers check if the date is valid and return a date with month written in a word if it's not valid date the program should stop and exit


#include <iostream>
using namespace std;
int main()

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
{
	int day,month,year;
	
	  cout<<"enter day\n";
	  cin>>day;
	  cout<<"enter month\n";
	  cin>>month;
	  cout<<"enter year\n";
	  cin>>year;
	  if (((month=1|| month=3 || month=5 || month=7 || month=8 || month=10 || month=12) && (1<day<31)) &&

		  ((month=4 || month=6 || month=9 || month=11 && (1>day>30)) &&

		  ((month=2) && (day=28) && (0>year>3000))))
	  
			 switch(month)
		      {
                case '1':
				cout<<day<<"/"<<"january/"<<year;
		          break;
		        case '2':
				cout<<day<<"/"<<"febuary/"<<year;
		         break;
		  
		  
				 case '3':
				cout<<day<<"/"<<"march/"<<year;
		  
				break;
	            case '4':
				cout<<day<<"/"<<"april/"<<year;


				break;
				 case '5':
				cout<<day<<"/"<<"may/"<<year;
				break;
				 
				 case '6':

				cout<<day<<"/"<<"june/"<<year;
				
				

				case '7':

				cout<<day<<"/"<<"july/"<<year;

				break;
				
				 case '8':

				cout<<day<<"/"<<"August/"<<year;


				break;

				 case '9':

				cout<<day<<"/"<<"September/"<<year;

				break;

				 case '10':
				cout<<day<<"/"<<"October/"<<year;


				break;

				 case '11':

				cout<<day<<"/"<<"November/"<<year;

				break;

				 case '12':

				cout<<day<<"/"<<"December/"<<year;

				

		          }
	  }
	  
	  else 
		  cout<<"false";
		 
	  

				
				


			return 0;
};


plz help i mloosing my mind :{}
Your first mistake: Don't use '='. use '==' for test for equality.

and delete the closing brace on 83.

edit: And sort this out:
(1 < day < 31)
This isn't really returning you a bool (or not how you think it is anyway)
Last edited on
take a look now:

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
#include <iostream>
using namespace std;
int main()
	
{
	int day,month,year;
	
	  cout<<"enter day\n";
	  cin>>day;
	  cout<<"enter month\n";
	  cin>>month;
	  cout<<"enter year\n";
	  cin>>year;
	  if ((((month==1)|| (month==3) || (month==5) || (month==7) || (month==8) || (month==10) || (month==12)) && (1<day<31)) &&

		  (((month==4) || (month==6) || (month==9) || (month==11) && (1<day>30)) &&

		  ((month==2) && (day==28) && (0<year<3000))))
	  {
			 switch(month)
		      {
                case '1':
				cout<<day<<"/"<<"january/"<<year;
		          break;
		        case '2':
				cout<<day<<"/"<<"febuary/"<<year;
		         break;
		  
		  
				 case '3':
				cout<<day<<"/"<<"march/"<<year;
		  
				break;
	            case '4':
				cout<<day<<"/"<<"april/"<<year;


				break;
				 case '5':
				cout<<day<<"/"<<"may/"<<year;
				break;
				 
				 case '6':

				cout<<day<<"/"<<"june/"<<year;
				
				

				case '7':

				cout<<day<<"/"<<"july/"<<year;

				break;
				
				 case '8':

				cout<<day<<"/"<<"August/"<<year;


				break;

				 case '9':

				cout<<day<<"/"<<"September/"<<year;

				break;

				 case '10':
				cout<<day<<"/"<<"October/"<<year;


				break;

				 case '11':

				cout<<day<<"/"<<"November/"<<year;

				break;

				 case '12':

				cout<<day<<"/"<<"December/"<<year;

				

		          }
	  }
	  
	  else 
		  cout<<"false";
		 
	  

				
				


			return 0;
};


it still returning false when i put
day-27
month-5
-year-1990
why???
Last edited on
you've ignored my last point. Check my edit :)

In essence, do not handle all of that logic in one if statement.

also month is an int, but your switch is checking characters:

case '1':
Last edited on
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
#include <iostream>
using namespace std;
int main()
	
{
	int day,month,year;
	
	  cout<<"enter day\n";
	  cin>>day;
	  cout<<"enter month\n";
	  cin>>month;
	  cout<<"enter year\n";
	  cin>>year;
	  if ((((month==1)|| (month==3) || (month==5) || (month==7) || (month==8) || (month==10) || (month==12)) && ((day<31) && (day>1))) &&

		  (((month==4) || (month==6) || (month==9) || (month==11) && ((day<30) && (day>1)))) &&

		  ((month==2) && (day==28) && (((year<3000) && (year>0)))))
	  {
			 switch(month)
		      {
                case '1':
				cout<<day<<"/"<<"january/"<<year;
		          break;
		        case '2':
				cout<<day<<"/"<<"febuary/"<<year;
		         break;
		  
		  
				 case '3':
				cout<<day<<"/"<<"march/"<<year;
		  
				break;
	            case '4':
				cout<<day<<"/"<<"april/"<<year;


				break;
				 case '5':
				cout<<day<<"/"<<"may/"<<year;
				break;
				 
				 case '6':

				cout<<day<<"/"<<"june/"<<year;
				
				

				case '7':

				cout<<day<<"/"<<"july/"<<year;

				break;
				
				 case '8':

				cout<<day<<"/"<<"August/"<<year;


				break;

				 case '9':

				cout<<day<<"/"<<"September/"<<year;

				break;

				 case '10':
				cout<<day<<"/"<<"October/"<<year;


				break;

				 case '11':

				cout<<day<<"/"<<"November/"<<year;

				break;

				 case '12':

				cout<<day<<"/"<<"December/"<<year;

				

		          }
	  }
	  
	  else 
		  cout<<"false";
		 
	  

				
				


			return 0;
};


still returning false....
Check mutexe's answer. The edited part.
mutexe wrote:
And sort this out:
(1 < day < 31)
This isn't really returning you a bool (or not how you think it is anyway)


Don't use conditionals like this (1<day<31).

Use
(1<=day)&&(day>=31)
instead.
Note the '=' signs because you want both values included.
still returning false allways :/
maybe my if line is not good?
dude, what's the point if you're not gonna listen to my posts?
im sorry bro'
didn't saw your'e last post
how can i do this?
i mean how can i arrange the if line
and how can i use switch for integers?
if ( ( (((month==1)|| (month==3)|| (month==5)|| (month==7)|| (month==8)|| (month==10)|| (month==12) )&&((day<32)&&(day>0))) || (((month==4)|| (month==6)|| (month==9)|| (month==11))&&((day<31)&&(day>0))) || ((month==2)&&((day<29)&&(day>0))) ) && ((year>-1)&&(year<3001)) )

hows that if line better?
look at it now :

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
{
	int day,month,year;
	
	  cout<<"enter day\n";
	  cin>>day;
	  cout<<"enter month\n";
	  cin>>month;
	  cout<<"enter year\n";
	  cin>>year;
	 if (     (   (((month==1)|| (month==3)|| (month==5)|| (month==7)|| (month==8)|| (month==10)|| (month==12) )&&((day<32)&&(day>0)))      ||      (((month==4)|| (month==6)|| (month==9)|| (month==11))&&((day<31)&&(day>0)))  ||  ((month==2)&&((day<29)&&(day>0)))  ) && ((year>-1)&&(year<3001))   )
	 {
			 switch(month)
		      {
                case 1:
				cout<<day<<"/"<<"january/"<<year;
		          break;
		        case 2:
				cout<<day<<"/"<<"febuary/"<<year;
		         break;
		  
		  
				 case 3:
				cout<<day<<"/"<<"march/"<<year;
		  
				break;
	            case 4:
				cout<<day<<"/"<<"april/"<<year;


				break;
				 case 5:
				cout<<day<<"/"<<"may/"<<year;
				break;
				 
				 case 6:

				cout<<day<<"/"<<"june/"<<year;
				
				

				case 7:

				cout<<day<<"/"<<"july/"<<year;

				break;
				
				 case 8:

				cout<<day<<"/"<<"August/"<<year;


				break;

				 case 9:

				cout<<day<<"/"<<"September/"<<year;

				break;

				 case 10:
				cout<<day<<"/"<<"October/"<<year;


				break;

				 case 11:

				cout<<day<<"/"<<"November/"<<year;

				break;

				 case 12:

				cout<<day<<"/"<<"December/"<<year;
				default;
				cout<<"not correct";
				
               }

	 }
	  else 
		 
	  {
			  cout<<"false";
	  
	 
	  }
	  
		 
	  

				
				


			return 0;
};
You could try something like this:
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<iostream>

bool ValidMonth(int month)
{
	bool rtn(false);

	if ((month >= 1) && month <= 12)
	{
		rtn = true;
	}

	return rtn;
}

bool validDay(int day, int month)
{
	bool rtn(false);

	// NOTE: i don't know how many days are in each month, but this is the kinda way you might wanna go about it
	switch (month)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
		if (day>=1 && day <=31)
		{
			rtn = true;
		}
		break;
	case 2:
		if (day >= 1 && day <= 28) // or 29 if leap
		{
			rtn = true;
		}
		break;
	default:
		// whatever
		break;
	}
	return rtn;
}

bool validYear(int year)
{
	bool rtn(false);

	if (year >= 0 && year <= 3000)
	{
		rtn = true;
	}

	return rtn;
}


int main()
{

	int day, month, year;

	std::cout << "enter day\n";
	std::cin >> day;
	std::cout << "enter month\n";
	std::cin >> month;
	std::cout << "enter year\n";
	std::cin >> year;

	if (validDay(day, month) && ValidMonth(month) && validYear(year))
	{
		// do your switch for the month as you are doing

	}

}


NOTE: i haven't completed the logic for how many days in the month of interest, but you get the idea.
Topic archived. No new replies allowed.