Home > Back-end >  Come to a big, vs2010 after running the input parameters in the c programming, press enter directly
Come to a big, vs2010 after running the input parameters in the c programming, press enter directly

Time:09-26

#include ?
Void main ()
{
Int year;
Int the month, maxmonth=12;
Int day, maxday;
Printf (" please enter the year (1000 ~ 3000) ");
The scanf (" % d ", & amp; Year);
If (year<1000 | | year> 3000)
{
Printf (" input error! Please input the new! \n");
Printf (" please enter the year (1000 ~ 3000) ");
The scanf (" % d ", & amp; Year);
}
Printf (" please enter the month (1 ~ 12) ");
The scanf (" % d ", & amp; The month);
If (month<1 | | month> 12)
{
Printf (" input error! Please input the new! \n");
Printf (" please enter the month (1 ~ 12) ");
The scanf (" % d ", & amp; The month);
}
If (the month==4 | | the month 6==| | 9 month==| | the month==11)
Maxday=30;
Else if (the month==2)
{
If (year %==0 400 | | year % 4==0)
Maxday=28;
The else
Maxday=29;
}
The else
Maxday=31;
Printf (" please enter the day of (1 ~ 31) ");
The scanf (" % d ", & amp; Day);
If (day<1 | | day> Maxday)
{
Printf (" input error! Please input the new! \n");
Printf (" please enter the day of (1 ~ 31) ");
The scanf (" % d ", & amp; Day);
}
If (the month==maxmonth & amp; & Day==maxday)
{
Year=year + 1;
The month=1;
Day=1;
}
Else if (day==maxday)
{
The month=month + 1;
Day=1;
}
The else
Day=day + 1;
Printf (" the next day is on % d % d % d ", year, month, day);
getchar();

}

Press enter exit not compile the results automatically

CodePudding user response:

Look will go to the printf ah, you save compile?

CodePudding user response:

Press the "Enter" key, the buffer will be "wrap" character, this will also be getchar () take, you can try call twice getchar (), or call system (" pause "); (need to include the header file # include & lt; Windows. H>)

CodePudding user response:

 # include 
//void main ()
Int main ()
{
Int year;
Int the month, maxmonth=12;
Int day, maxday;
Printf (" please enter the year (1000 ~ 3000) ");
The scanf (" % d ", & amp; Year);
//if (year<1000 | | year> 3000)
While (year<1000 | | year> 3000)
{
Printf (" input error! Please input the new! \n");
Printf (" please enter the year (1000 ~ 3000) ");
The scanf (" % d ", & amp; Year);
}
Printf (" please enter the month (1 ~ 12) ");
The scanf (" % d ", & amp; The month);
//if (month<1 | | month> 12)
While (month<1 | | month> 12)
{
Printf (" input error! Please input the new! \n");
Printf (" please enter the month (1 ~ 12) ");
The scanf (" % d ", & amp; The month);
}
If (the month==4 | | the month 6==| | 9 month==| | the month==11)
Maxday=30;
Else if (the month==2)
{
//if (year %==0 400 | | year % 4==0)
If (year %==0 400 | | (year % 4==0 & amp; & Year % 100!=0))
Maxday=28;
The else
Maxday=29;
}
The else
Maxday=31;
Printf (" please enter the day of (1 ~ 31) ");
The scanf (" % d ", & amp; Day);
//if (day<1 | | day> Maxday)
While (day<1 | | day> Maxday)
{
Printf (" input error! Please input the new! \n");
Printf (" please enter the day of (1 ~ 31) ");
The scanf (" % d ", & amp; Day);
}
If (the month==maxmonth & amp; & Day==maxday)
{
Year=year + 1;
The month=1;
Day=1;
}
Else if (day==maxday)
{
The month=month + 1;
Day=1;
}
The else
Day=day + 1;
Printf (" the next day is on % d % d % d ", year, month, day);
getchar();

}

For your reference ~

CodePudding user response:

reference 1/f, arfi response:
look will go to the printf ah, you save compile?
sure feel not code issue is other I in the rest of the code, and compile input not only compiled output

CodePudding user response:

With this system (" pause ") seems to be ok but not the other

CodePudding user response:

refer to 6th floor ek11one response:
add this system (" pause ") seems to be ok but not other


You this is compiled to run, not run in the ide, so after the program will automatically close CMD window
Originally used getchar suspend your program can also blocking (IO), just in front of you you have placed carriage returns in the input of the residues in the input buffer, so getchar directly to a carriage return to continue to run down the end of the program, so at the end of the program in the system (" pause ") to suspend your program can not end
You said no other is to point to? Refers to the getchar not? That you before getchar plus fflush (stdin) try to clear the input buffer
  • Related