Hi, new to the boards and in fact im new to programming as well. right now im taking my first C programming class and its going fairly well. its fun and interesting but tends to eat up a bunch of my time...
but anyways here is my first question...
im working on a group assignment right now, the assignment was split into 4 separate programs. each program builds on itself in a way that the prior program becomes a function for the next. the problem i am having is trying to understand one of my group member's program. apparently he got his older brother to help him so my partner cant really explain whats happening very well. the purpose of his program was for a user to input a start date and end date then the program to compute the numbers of days in between them.
the 3 main things im having trouble with is...
1. when in the program it state "diff = diff + DAYSOF(startyear); " can we use the "++" function for this? and how?
2. what exactly are these 3 lines of code for?
Code:
tempday=startday; startday=endday; endday=tempday;
tempmonth=startmonth; startmonth=endmonth; endmonth=tempmonth;
tempyear=startyear; startyear=endyear; endyear=tempyear;
3.and this macro "#define DAYSOF(x) (is_leap(x)?DAYSINLEAPAYSINYEAR)" is this the same as a if then statement?
Code:
#include <stdio.h>
#include "tfdef.h"
#include "leap.h"
#include "days.h"
#include "julian.h"
#define DAYSINLEAP 366
#define DAYSINYEAR 365
#define DAYSOF(x) (is_leap(x)?DAYSINLEAP:DAYSINYEAR)
main()
{ /* start function main */
/* variable declarations */
int flag;
int startday, startmonth, startyear;
int endday, endmonth, endyear;
int tempday, tempmonth, tempyear;
int diff;
/* prompt user for initial start date */
printf("EOF to quit\n");
printf("Enter integer start date <month> <day> <year>: ");
flag = scanf("%d %d %d",&startmonth,&startday,&startyear);
while (flag!=EOF)
{ /* start while loop */
/* prompt user for end date */
printf("Enter integer end date <month> <day> <year>: ");
scanf("%d %d %d",&endmonth,&endday,&endyear);
/* exchange start and end dates for circumstance */
if (startyear>endyear)
{ /* start if statement */
tempday=startday; startday=endday; endday=tempday;
tempmonth=startmonth; startmonth=endmonth; endmonth=tempmonth;
tempyear=startyear; startyear=endyear; endyear=tempyear;
} /* END IF STATEMENT */
if ( (startyear==endyear)&&(startmonth>endmonth) )
{ /* START IF STATEMENT */
tempday=startday; startday=endday; endday=tempday;
tempmonth=startmonth; startmonth=endmonth; endmonth=tempmonth;
tempyear=startyear; startyear=endyear; endyear=tempyear;
} /* end if statement */
if ( (startyear==endyear)&&(startmonth==endmonth)&&(startday>endday) )
{ /* start if statement */
tempday=startday; startday=endday; endday=tempday;
tempmonth=startmonth; startmonth=endmonth; endmonth=tempmonth;
tempyear=startyear; startyear=endyear; endyear=tempyear;
} /* end if statement */
if (startyear==endyear)
diff = julian_date(endday, endmonth, endyear)-
julian_date(startday, startmonth, startyear);
else
{ /* start if statement */
/* calculate from start to end of its year */
/* and from end to beginning of its year */
diff = julian_date(endday, endmonth, endyear)+
DAYSOF(startyear)-
julian_date(startday, startmonth, startyear);
/* add all days from the 'between' years */
startyear+=1;
while(startyear<endyear)
{ /* start while loop */
diff = diff + DAYSOF(startyear);
startyear++;
} /* end while loop */
} /* end else statement */
printf("The date difference is %d days.\n",diff);
/* prompt user for new start and end dates */
printf("Enter integer start date <month> <day> <year>: ");
flag=scanf("%d %d %d",&startmonth,&startday,&startyear);
} /* end while loop */
} /* end function main */
i know, kinda long.........sorry.