Why is this not outputting correctly?

Oct 27, 2014 at 8:20am
Why in the world will this not detect which year is entered and choose to output the right statement for the right year. No matter what I enter, it chooses the first if statement

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
  if (year >= 1582 || year <=2013)
	{
	cout << "\n The date " << month << "/" << day << "/" << year 
		 << " was a "; 	
	}
	else if (year == 2014)
	{
	cout << "\n The date " << month << "/" << day << "/" << year 
		 << " is a "; 
	}
	else if (year > 2014) 
	{
	cout << "\n The date " << month << "/" << day << "/" << year 
		 << " will be a ";
	}
	
     switch(day_of_week)
     {
        case SUNDAY: cout << "Sunday."; break;
        case MONDAY: cout << "Monday."; break;
        case TUESDAY: cout << "Tuesday."; break;
        case WEDNESDAY: cout << "Wednesday."; break;
        case THURSDAY: cout << "Thursday."; break;
        case FRIDAY: cout << "Friday."; break;
        case SATURDAY: cout << "Saturday."; break;
 	 }
Last edited on Oct 27, 2014 at 8:20am
Oct 27, 2014 at 8:35am
Because the condition year >= 1582 || year <= 2013 is always true.
Oct 27, 2014 at 8:58am
How would I fix the problem?
Oct 27, 2014 at 11:03am
I think you want && in line 1 instead of ||. && means "and" and || means "or". The reason the condition is always true is because every number is either greater than 1582 or less than 2013 - some numbers are both.
Topic archived. No new replies allowed.