Reputation: 1711
I am having hard time updating two arrays - the code below seems to update only update two days.
int month[365], day[365];
int countMonths[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int i = 0;
int currentmonth = 0;
int currentday = 1;
while(i < 365 && i < countMonths[currentmonth])
{
month[i] = currentmonth+1;
day[i] = currentday;
i++;
currentday++;
if(currentday > countMonths[currentmonth]);
{
currentmonth++;
currentday = 1;
}
}
Upvotes: 1
Views: 57
Reputation: 761
The problem is you have this condition in your while loop: i < countMonths[currentmonth]
- you stop iterating (because i
will be 29 and countMonths[1]
is 28), that's why your month isn't incrementing. Keep only the first condition and you should be good.
Upvotes: 1
Reputation: 118001
On your if
statement, you have an extra semi-colon
if(currentday > countMonths[currentmonth]);
You should not have that there.
Upvotes: 2