+ 1

HELP!

Hi guys .. so i made a code that calculates the days passed between two dates i dont know where is the problem https://code.sololearn.com/cE1jsxAYj7jd/?ref=app

7th Mar 2019, 10:51 AM
Dynno
Dynno - avatar
6 Réponses
+ 1
https://code.sololearn.com/cKdcvIUnL6Mv/#c
7th Mar 2019, 3:23 PM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
0
Your code for me is not clearly readable. 1. First of all modify the three scnafs into one: scanf("%d %d %d", &d1.day, &d1.month, &d1.year); instead of scanf("%d",& d1.day); scanf("%d",& d1.month); scanf("%d",& d1.year ); Check user input printf("Date 1:%d/%d/%d\n\n",d1.day, d1.month, d1.year); printf("Date 2:%d/%d/%d\n\n",d2.day, d2.month, d2.year); -- ---------------------------- 2. If there are cases in switch with the same result try to write it as case 1 : case 3 : case 5 : case 7 : case 8 : case 12 : DAYS+=d3.month*31; break; -- ---------------------------- 3. then your code is complicated. try to split it into functions. for example for your switch statement create a function to return days int findDays(date d3){ switch (d3.month ){ case 1 : case 3 : case 5 : case 7 : case 8 : case 12 : d3.day=31+d3.day; break; case 4 : case 6 : case 9 : case 11 : d3.day=30+d3.day; break; case 2 : if ((( d3.year % 4 ==0 ) && (d3.year%100 != 0)) || (d3.year%400 ==0)){ d3.day=29+d3.day; } else { d3.day=28+d3.day; } break; } // emnd of switch return d3.day; } Continue as above and I think that you will find your error
7th Mar 2019, 11:58 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
0
Prokopios Poulimenos oh there is a lot of infos in your comment that i didn't knew about thanks man. I will try fix what i can
7th Mar 2019, 1:38 PM
Dynno
Dynno - avatar
0
Prokopios Poulimenos is it ok not to put "/" in the scanf ? edit. : my bad. i thought that printf. a scanf xD
7th Mar 2019, 1:52 PM
Dynno
Dynno - avatar
0
Yes, you can do it scanf("%d/%d/%d", &d1.day, &d1.month, &d1.year); But then your input should be in format dd/mm/yyyy
7th Mar 2019, 2:08 PM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
0
Prokopios Poulimenos wow you did it ... why i'm not good in C 🙁😞 there is a lot of stuff i don't know about
7th Mar 2019, 4:22 PM
Dynno
Dynno - avatar