Please help, With Julian format

Good day guys,

Could you please help with adding the days In my array, because im not getting the correct answer.
An ie. user types in 27 3. Output should be 86 .(31(jan) +28(feb) +27(march))

This is just part of my coding and yes im not done, I just want to rectify the calculations to do with my first date before I continue.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include<iostream>
#include<cassert>
using namespace std;

int main()
{
   int day1,day2,month1,month2, validate_date1, validate_date2;
   int daysPerMonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
   const int Maximum_month = 12;
   int Sum_of_date1 = 0;//,Sum_of_date2;

   cout<<"Enter the First date : ";
   cin>>day1>>month1;
   cout<<endl;
   cout<<"Enter the Second date : ";
   cin>>day2>>month2;
   cout<<endl;

   validate_date1 = daysPerMonth[month1];
   validate_date2 = daysPerMonth[month2];

   assert(day1<= validate_date1 && day2 <= validate_date2 && month1 <= Maximum_month && month2 <= Maximum_month );

   int counter = 0;

   while (counter < 1)
   {
      if (counter == 0)
         {
            for(int i = 1; i <= daysPerMonth[month1] ; i++)
            {
               //my problem starts here
               Sum_of_date1 += daysPerMonth[i + 1];
            }
            cout<<Sum_of_date1;

         }
         counter++;
   }


Loop while Why???

Try this code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
   int counter = 0;
 
   while (counter < 1)
   {
      if (counter == 0)
         {
            for(int i = 1; i <= daysPerMonth[month1] ; i++)]
            {
               //my problem starts here
               Sum_of_date1 += daysPerMonth[i];
            }
            cout<<Sum_of_date1;
 
         }
         counter++;
   }*/
  
  
  int delta =0;
  
  for (int i = month1 - 1 ; i< month2; i++)
    {
      delta += daysPerMonth[i];
     }
  int total_days = delta -  day1 - ( daysPerMonth[month2 - 1] - day2 );
 
  cout << total_days;
  
  }
 
Topic archived. No new replies allowed.