Hello ladies and gents,
I was making this small exercise in wich I have to enter a certain date meaning, day, month and year.
If entered it should count the amount of days from the beginning of that year and print it.
I found a solution for this, but was wondering wether there is an alternative or maybe somethings you might change in this code. I know that there is a certain library wich makes this automatically, but then again, it wouldn't be much of an exercise now would it ;)
The code is:
int main()
{
int dag, maand;
int month= 1, year=0, amount=0;
cin>> dag;cin.get();
cin>> maand;cin.get();
cin>> year;cin.get();
int tabel[12]={31,28,31,30,31,30,31,31,30,31,30,31};
tabel[1]=28+(year%4==0 && year%100 !=0 || year %400==0);
for (int i=0;i<maand;i++)
{
if(month!=maand)
{
amount+=tabel[i];
month++;
}
}
for (int day=0; day<dag; day++)
{
{
amount++;
}
}
cout<<amount<<endl;
return 0;
}