For an assignment we are supposed to read in a list of dates and associated values (temperatures) from a text document. Values in each line are separated by commas.
Example data:
dd,mm,yyyy,x,y,z,w
01,01,2011,1.1,5.2,6.5,7.5
02,01,2011,2.1,5.2,6.1,1.1
03,01,2011,4.5,2.5,6.1,2.1
...
30,01,2011,4.1,6.1,6.1,2.1
01,02,2011,2.5,6.1,7.1,6.3
So far I have implemented a loop to read each line:
while(scanf("%d,%d,%d,%f,%f,%f,%f", &dd, &mm, &yyyy, &x, &y, &z, &w) == 7)
{
}
We’re given the assumption that there are no errors in the document, and no duplicate dates.
However, there may be missing entries (not each month have complete data; missing days).
I am having trouble detecting if each month’s data (mm) is a complete month or only a partial month.
Eg: 31 days in March 2011. If I have 31 entries from March, I need to print ‘Full month’, otherwise if there are missing days I have to print ‘Partial month’.
So far I have been using if(mm==1){} statements to separate each month inside the while(scanf(...)) loop and then incrementing them in separate variables, then comparing it with the amount of days in a complete month, but I don’t know how to implement it so it detects that mm has changed from the previous line (new month) and perform a certain action (e.g.: calculations)
Sorry if this is confusing!
We have not been taught arrays yet, only operations, loops and functions.
keep prev month value somewhere; finalize monthly related computations and reset the monthly counters when the month you are reading is higher than prev month