c언어 날짜계산
아이
질문 제목 :
c언어 날짜계산
c언어 오류질문 내용 :오류는 안나는데 기준일자로부터 같은달안에 있는 수를 입력하면 맞게 출력이 되는데(ex:10일후 ) 100일 후 같은
다른 달로 넘어가야 하는 날짜를 입력하면 아래의 사진과 같이 잘못 출력이 됩니다ㅠ-ㅠ 소스를 어떻게 고쳐야 할까요..?
#include iostreamusing namespace std;
void calc_numdates(int, int);
int main(){
int begin_date, date_count; while(true) {
do
{
printf(기준일자를 입력하세요(yyyymmdd) : );
cin begin_date;
if (begin_date == 0) return 0;
} while (begin_date/100009999 || begin_date%10000/10012 || begin_date%10031);
printf(기준일자로 부터의 날짜수를 입력하세요 : );
cin date_count;
calc_numdates(begin_date, date_count);
} // end of while
} // end of main
void calc_numdates(int begin_date, int date_count)
{
int year, month, day, end_year=0, end_month=0, end_day=0;
int month_days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool isleapyear;
year = begin_date/10000;
month = begin_date%10000/100;
day = begin_date%100; isleapyear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
if (isleapyear) month_days[1]=29;
// 윤년인 경우 2월을 29일로 계산
for(int i= month-1;; i++)
{
if (date_count - (month_days[i]-day+1) =0)
{
end_month = month + end_month ;
end_day = day + date_count -1;
end_year = year;
break; }
else
{
date_count -= month_days[i]-day+1;
day = 1; }
} printf(%d년%d월%d일 입니다. \n,end_year,end_month,end_day);
return;
}
d
-
퍼리
이 질문은 C++ 질문 게시판으로 옮기는게 좋겠네요.
그리고 소스를 문제 있는 일부분만 올려주시고 설명을 주석으로 해주시면 보기가 편할꺼 같아요 ^^
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |