Home > Back-end >  C beginners ask god for help
C beginners ask god for help

Time:10-11

I wrote so why not
#include
using namespace std;

The class Date
{
Public: Date (int y, int m, int d) {year=y; The month=m; Day=d; All=0; Days=0; } int myday (); Private: int year, month, day, all the days; };

Int the Date: : myday ()
{
Int all days;
The switch (month)
{case 1: all=0; break; Case 2: all=31; break; Case 3: all=59; break; Case 4: all=90; break; Case 5: all=120; break; Case 6: all=151; break; Case 7: all=181; break; Case 8: all=212; break; Case 9: all=243; break; Case 10: all=273; break; Case 11: all=304; break; Case 12: all=334; break; If (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; }}
The return days;
}
Int main ()
{int y, m, d;
Cin> Y> M> d;
The Date my (y, m, d);
My myday ();
cout}

CodePudding user response:

You switch of curly braces is wrong, in case12 break, namely the if leap year judgment to remove the switch of curly braces,
The
12: all=334; break; If (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; } }
Change
12: all=334; break; } the if (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; }

In addition to write code as indentation, best or out of the problem is not good looking for you this is not trouble yourself

CodePudding user response:

reference 1st floor qybao response:
you switch the curly braces is wrong, on case12 break behind, namely the if leap year judgment to remove the switch of curly braces,
The
12: all=334; break; If (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; } }
Change
12: all=334; break; } the if (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; }

In addition to write code as indentation, best or out of the problem is not good looking for you this is not trouble yourself
thank you?? , I was written in indentation code is copied to the changed here
According to your changed after how or not

CodePudding user response:

reference 1st floor qybao response:
you switch the curly braces is wrong, on case12 break behind, namely the if leap year judgment to remove the switch of curly braces,
The
12: all=334; break; If (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; } }
Change
12: all=334; break; } the if (year % 4==0 & amp; & Year % 100!=0 | | year %==0 400) {if (month> 3) {days=all + day + 1; }} else {days=all + day; }

Also best to write code as indentation, or a problem with not good looking for you this is not trouble yourself
I found there is a wrong brackets
The inside of the if statement
  • Related