Why is my loop not working?

Why is my loop not working? Can you please help me fix it?

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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  #include <iostream> 

using namespace std; 
  
const int JANUARY   = 1; 
const int FEBRUARY  = 2; 
const int MARCH     = 3; 
const int APRIL     = 4; 
const int MAY       = 5; 
const int JUNE      = 6; 
const int JULY      = 7; 
const int AUGUST    = 8; 
const int SEPTEMBER = 9; 
const int OCTOBER   = 10; 
const int NOVEMBER  = 11; 
const int DECEMBER  = 12; 

// Returns true if the given year is a leap year
bool is_leap_year(int year); 
// Returns a value computed from the century of the year
int get_century_value(int year); 
// Returns a value computed based on the years since the beginning of the century.
int get_year_value(int year);
// Returns a value (from a table) for the given month  
int get_month_value(int month, int year);  

int main() 

{  
 
int month =0;
int day = 0; 
int year = 0;
int day_of_week = 0; 
int days_in_month = 0;
bool dates_invalid=true;

do
{
cout << endl;	
cout << " Please enter a month: "; 
cin >> month; 
cout << endl;
cout << " Please enter a day: "; 
cin >> day;
cout << endl;
cout << " Please enter a year: "; 
cin >> year;

//check for leap year
if(month == 9 || month == 4 || month == 6  || month == 11)
	{
		days_in_month = 30;

	}
	else if(month == 2)
	{ 
		if( (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
		{
			days_in_month = 29;
		}
		else
		{
			days_in_month = 28;
		}
	}
	else
	{
		days_in_month = 31;
	}


	if( month < 1 || month > 12 || day <= 0 || day > days_in_month)
	{
		cout << endl;
		cout << "You have entered an invalid date. Please try again." << endl;
		dates_invalid=false;
		cout << endl;
	}

else 

	dates_invalid = true;
}
    while (dates_invalid=false);
	

// Compute the day of the week
day_of_week = day + get_month_value(month, year) + get_year_value(year) + get_century_value(year);    
    
day_of_week = day_of_week % 7; 
 
cout << "\n The date " << month << "/" << day << "/" << year 
     << " is a ";  

    if (day_of_week == 0) 
    { 
		cout << "Sunday."; 
    }  
    else if (day_of_week == 1) 
    { 
		cout << "Monday."; 
    }  
    else if (day_of_week == 2) 
    { 
		cout << "Tuesday."; 
    }  
    else if (day_of_week == 3) 
    { 
		cout << "Wednesday."; 
    }  
    else if (day_of_week == 4) 
    { 
		cout << "Thursday."; 
    }  
    else if (day_of_week == 5) 
    { 
		cout << "Friday."; 
    }  
    else if (day_of_week == 6) 
    { 
		cout << "Saturday."; 
    }  
    cout << endl; 
    return 0; 
}

// Prompts the user to input a month, day and year 
void get_input(int month, int day, int year) 

{  
	cout << endl;
	cout << " Please enter a month: "; 
    cin >> month; 
    cout << endl;
    cout << " Please enter a day: "; 
    cin >> day;
    cout << endl;
    cout << " Please enter a year: "; 
	cout << endl;
    cin >> year;
}

// Returns true if the given year is a leap year 

bool is_leap_year(int year) 

{  
    return (((year % 400) == 0) ||(((year % 4) == 0) 
	&& ((year % 100) != 0))); 

} 

// Returns a value computed from the century of the year 

int get_century_value(int year) 

{  
    int century;
	int remainder; 
    century = year/100;  
    remainder = (century % 4); 
    return ((3 - remainder) * 2); 
}

// Returns a value computed based on the years since 
// the beginning of the century. 
int get_year_value(int year) 

{  
    int sinceCentury;  
    sinceCentury = year % 100;  
    return (sinceCentury + (sinceCentury/4)); 
} 

// Returns a value (from a table) for the given month 

int get_month_value(int month, int year) 
{  
    int result;  
    if (month == JANUARY) 
    { 
		if (is_leap_year(year))  
        { 
    		result = 6; 
        } 
        else 
		{ 
    		result = 0; 
		} 
	}
    if (month == FEBRUARY) 
	{ 
		if (is_leap_year(year))  
        { 
    		result = 2; 
        } 
        else 
		{ 
    		result = 3; 
		} 

	}
    else if (month == MARCH) 

    	{ 
			result = 3; 
    	}  

    else if (month == APRIL) 

    { 
		result = 6; 
    }  

    else if (month == MAY) 

    { 
		result = 1; 
    }  

    else if (month == JUNE) 

    { 
		result = 4; 
    }  

    else if (month == JULY) 

    { 
		result = 6; 
    }  

    else if (month == AUGUST) 

    { 
		result = 2; 
    }  

    else if (month == SEPTEMBER) 

    { 
		result = 5; 
    }  

    else if (month == OCTOBER) 

    { 
		result = 0;
    }  

    else if (month == NOVEMBER) 

    { 
		result = 3; 
    }  

    else if (month == DECEMBER) 

    { 
		result = 5; 
    } 
  
    return result; 
	
}
closed account (2UD8vCM9)
Line 85
 
while (dates_invalid=false);


You are not checking anything here, so your loop will never end.

One equals sign is assignment.

Two equals sign is comparison.


You need to change this to

 
while (dates_invalid==false);
Topic archived. No new replies allowed.