[問題] 利用函式找出明天
看板C_and_CPP (C/C++)作者obelisk0114 (追風箏的孩子)時間13年前 (2011/10/13 14:21)推噓13(13推 0噓 86→)留言99則, 22人參與討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++ 2008
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
輸入日期,找出明天
餵入的資料(Input):
鍵盤輸入月,日,年
預期的正確結果(Expected Output):
跑出明天的日期
錯誤結果(Wrong Output):
無法顯示結果
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;
int a,b,c,d,e;
double f;
void LeapYear(int c)
{
if(e!=f){
cout<<"It is not a leap year!\n";}
}
void incrementDate(int& a, int& b, int& c);
void incrementDate(int& a, int& b, int& c)
{
d=b+1;
if(a>12 || a<1){
cout<<"Wrong!\n";}
else if(b<1){
cout<<"Wrong!\n";}
else if(c<1){
cout<<"Wrong!\n";}
else{
if(a==1 && b>31){
cout<<"Wrong!\n";}
else if(a==2 && b>29){
cout<<"Wrong!\n";}
else if(a==2 && b==29){
LeapYear(c);}
else if(a==3 && b>31){
cout<<"Wrong!\n";}
else if(a==4 && b>30){
cout<<"Wrong!\n";}
else if(a==5 && b>31){
cout<<"Wrong!\n";}
else if(a==6 && b>30){
cout<<"Wrong!\n";}
else if(a==7 && b>31){
cout<<"Wrong!\n";}
else if(a==8 && b>31){
cout<<"Wrong!\n";}
else if(a==9 && b>30){
cout<<"Wrong!\n";}
else if(a==10 && b>31){
cout<<"Wrong!\n";}
else if(a==11 && b>30){
cout<<"Wrong!\n";}
else if(a==12 && b>31){
cout<<"Wrong!\n";}
}
if(a==1 && d<32){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==1 && d==32){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==2 && d<29){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==2 && d==29){
if(e==f){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else{
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
}
else if(a==2 && d==30){
if(e==f){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
}
else if(a==3 && d<32){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==3 && d==32){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==4 && d<31){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==4 && d==31){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==5 && d<32){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==5 && d==32){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==6 && d<31){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==6 && d==31){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==7 && d<32){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==7 && d==32){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==8 && d<32){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==8 && d==32){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==9 && d<31){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==9 && d==31){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==10 && d<32){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==10 && d==32){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==11 && d<31){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==11 && d==31){
cout<<"Tomorrow is "<<a+1<<"/1/"<<c<<"\n";}
else if(a==12 && d<32){
cout<<"Tomorrow is "<<a<<"/"<<d<<"/"<<c<<"\n";}
else if(a==12 && d==32){
cout<<"Tomorrow is "<<1<<"/1/"<<c+1<<"\n";}
}
int main()
{
cout<<"Please input the month in integers:\n";
cin>>a;
cout<<"Please input the date:\n";
cin>>b;
cout<<"Please input the year:\n";
cin>>c;
e=c/4;
f=(double) c/4;
incrementDate(a,b,c);
return 0;
}
補充說明(Supplement):
--
│ ███ ▂▄▃ ││││
│ ˋ ◤Mooncat~◥││││ 「為什麼,
│ ‵ ◤ ◥▏*_▂▁ ▋ │││ 為什麼教授這麼靠盃
│ ′ 、▌█ ▊▉▏ │ 沒天理啊………」
◢ ◤◢ ◣▋◢ █ ▋▊ ▕▅▇ ◥◥*Mooncat~
◢ ▂▇ˋ█▆◤ ▂_ ▁▄▆▇▃ by mooncats
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.185
→
10/13 14:23, , 1F
10/13 14:23, 1F
→
10/13 14:24, , 2F
10/13 14:24, 2F
推
10/13 14:25, , 3F
10/13 14:25, 3F
→
10/13 14:26, , 4F
10/13 14:26, 4F
→
10/13 14:26, , 5F
10/13 14:26, 5F
→
10/13 14:28, , 6F
10/13 14:28, 6F
→
10/13 14:28, , 7F
10/13 14:28, 7F
→
10/13 14:34, , 8F
10/13 14:34, 8F
→
10/13 14:36, , 9F
10/13 14:36, 9F
→
10/13 14:38, , 10F
10/13 14:38, 10F
→
10/13 14:38, , 11F
10/13 14:38, 11F
→
10/13 14:40, , 12F
10/13 14:40, 12F
→
10/13 14:40, , 13F
10/13 14:40, 13F
→
10/13 14:42, , 14F
10/13 14:42, 14F
→
10/13 14:43, , 15F
10/13 14:43, 15F
→
10/13 14:43, , 16F
10/13 14:43, 16F
※ 編輯: obelisk0114 來自: 140.112.4.185 (10/13 14:45)
推
10/13 14:48, , 17F
10/13 14:48, 17F
最後完成版,編譯通過,感謝各位幫忙
※ 編輯: obelisk0114 來自: 140.112.4.185 (10/13 15:09)
→
10/13 15:09, , 18F
10/13 15:09, 18F
推
10/13 15:17, , 19F
10/13 15:17, 19F
→
10/13 15:19, , 20F
10/13 15:19, 20F
→
10/13 15:22, , 21F
10/13 15:22, 21F
→
10/13 15:23, , 22F
10/13 15:23, 22F
→
10/13 15:23, , 23F
10/13 15:23, 23F
→
10/13 15:23, , 24F
10/13 15:23, 24F
→
10/13 15:23, , 25F
10/13 15:23, 25F
→
10/13 15:28, , 26F
10/13 15:28, 26F
→
10/13 15:29, , 27F
10/13 15:29, 27F
→
10/13 15:33, , 28F
10/13 15:33, 28F
→
10/13 15:42, , 29F
10/13 15:42, 29F
→
10/13 15:43, , 30F
10/13 15:43, 30F
→
10/13 15:45, , 31F
10/13 15:45, 31F
→
10/13 15:58, , 32F
10/13 15:58, 32F
推
10/13 16:01, , 33F
10/13 16:01, 33F
→
10/13 16:22, , 34F
10/13 16:22, 34F
→
10/13 16:23, , 35F
10/13 16:23, 35F
→
10/13 16:24, , 36F
10/13 16:24, 36F
推
10/13 16:32, , 37F
10/13 16:32, 37F
還有 22 則推文
→
10/13 20:34, , 60F
10/13 20:34, 60F
推
10/13 21:39, , 61F
10/13 21:39, 61F
→
10/13 21:40, , 62F
10/13 21:40, 62F
→
10/13 21:54, , 63F
10/13 21:54, 63F
→
10/13 21:55, , 64F
10/13 21:55, 64F
→
10/13 22:01, , 65F
10/13 22:01, 65F
→
10/13 22:03, , 66F
10/13 22:03, 66F
→
10/13 22:04, , 67F
10/13 22:04, 67F
推
10/13 22:05, , 68F
10/13 22:05, 68F
→
10/13 22:07, , 69F
10/13 22:07, 69F
→
10/13 22:08, , 70F
10/13 22:08, 70F
推
10/14 08:08, , 71F
10/14 08:08, 71F
→
10/14 08:08, , 72F
10/14 08:08, 72F
→
10/14 08:08, , 73F
10/14 08:08, 73F
→
10/14 08:12, , 74F
10/14 08:12, 74F
→
10/14 08:42, , 75F
10/14 08:42, 75F
→
10/14 08:43, , 76F
10/14 08:43, 76F
→
10/14 08:43, , 77F
10/14 08:43, 77F
推
10/14 09:03, , 78F
10/14 09:03, 78F
→
10/14 09:47, , 79F
10/14 09:47, 79F
→
10/14 09:48, , 80F
10/14 09:48, 80F
推
10/14 10:16, , 81F
10/14 10:16, 81F
→
10/14 10:30, , 82F
10/14 10:30, 82F
→
10/14 10:30, , 83F
10/14 10:30, 83F
→
10/14 10:44, , 84F
10/14 10:44, 84F
→
10/14 12:40, , 85F
10/14 12:40, 85F
→
10/14 12:44, , 86F
10/14 12:44, 86F
→
10/14 13:14, , 87F
10/14 13:14, 87F
推
10/14 15:02, , 88F
10/14 15:02, 88F
→
10/14 15:03, , 89F
10/14 15:03, 89F
→
10/14 15:47, , 90F
10/14 15:47, 90F
→
10/14 15:47, , 91F
10/14 15:47, 91F
→
10/14 16:06, , 92F
10/14 16:06, 92F
→
10/16 01:41, , 93F
10/16 01:41, 93F
→
10/16 01:44, , 94F
10/16 01:44, 94F
→
10/16 01:45, , 95F
10/16 01:45, 95F
→
10/16 20:07, , 96F
10/16 20:07, 96F
→
10/16 20:07, , 97F
10/16 20:07, 97F
→
10/17 18:55, , 98F
10/17 18:55, 98F
→
10/17 18:55, , 99F
10/17 18:55, 99F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章