Hi,
I have the same problem. So far I have this code:
Code:
#include<stdio.h>
int main()
{
int month1, month2;
int NumDaysInEachMonth[] ={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int total;
int i;
int totalday =0;
int j;
int totalday2 =0;
do{
printf("\t\t\n\n ..... Number of days across two months program.....\n\n\n");
printf("\t 1........... January \n");
printf("\t 2........... Febuary \n");
printf("\t 3............. March \n");
printf("\t 4............. April \n");
printf("\t 5............... May \n");
printf("\t 6......... .....June \n");
printf("\t 7......... .....July \n");
printf("\t 8............ August \n");
printf("\t 9......... September \n");
printf("\t 10......... .October \n");
printf("\t 11......... November \n");
printf("\t 12......... December \n\n\n\n\n");
do{
printf("\t Please choose the first month (1-12)\n");
scanf("\t%d \n", &month1);
if (month1<1||month1>12) // error checking
printf("\tinvalid section, please enter another\n");
}
while(month1<1||month1>12); // loop until user enters a valid menu number
do{
printf("\tPlease enter a second month (1-12)");
scanf("\t %d \n", &month2);
if (month1<1||month1>12) // error checking
printf("\t invalid section please enter another\n");
}
while(month1<1||month1>12);
if
(i=month1, i<=month2, i++);
{
totalday = totalday+NumDaysInEachMonth[i];
}
if
(j=month2, j<=month1, j++);
{
totalday2 = totalday2+NumDaysInEachMonth[j];
}
printf("\t %d \n\n\n\n",totalday+=totalday2);
}
while (totalday<28||month1>62);
return 0;
}
for some reason now that i have the second if
Code:
if
(j=month2, j<=month1, j++);
{
totalday2 = totalday2+NumDaysInEachMonth[j];
}
it wont allow me to enter a second date. if I remove this and change the final printf. the program will allow me to enter two months and this will return how many days are in the final month. which is wrong because i want the program to return with the number of days across the two months the user inputted.
Could somebody give me an idea of were i have gone wrong. because at the moment i am clueless.
Tom.