From dd1be668ff33c87e15747a3bdd1e1ee1c0011987 Mon Sep 17 00:00:00 2001 From: Leaced Date: Sun, 2 Apr 2017 17:42:04 +0200 Subject: [PATCH] kleine Optimierung --- Kalender/weekday.cpp | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/Kalender/weekday.cpp b/Kalender/weekday.cpp index 0118820..c2a1002 100644 --- a/Kalender/weekday.cpp +++ b/Kalender/weekday.cpp @@ -59,34 +59,25 @@ int main() if(month==1 || month==2) year -=1; - switch (month) - { - case 1: month = 0; break; - case 8: month = 1; break; - case 2: - case 6: month = 3; break; - case 9: - case 12: month = 4; break; - case 4: - case 7: month = 5; break; - case 10: month = 6; break; - default: month = 2; break; - } + if(month==1) month = 0; + else if(month==8) month = 1; + else if(month==2 || month==6) month = 3; + else if(month==9 || month==12) month = 4; + else if(month==4 || month==7) month = 5; + else if(month == 10) month = 6; + else month = 2; weekday = (day+month+(year%100)+(year%100/4)+year/400-2*(year/100))%7; while(weekday<0) weekday += 7; - switch(weekday) - { - case 0: std::cout << "Sonntag"; break; - case 1: std::cout << "Montag"; break; - case 2: std::cout << "Dienstag"; break; - case 3: std::cout << "Mittwoch"; break; - case 4: std::cout << "Donnerstag"; break; - case 5: std::cout << "Freitag"; break; - case 6: std::cout << "Samstag"; break; - } + if(weekday==0) std::cout << "Sonntag"; + else if(weekday==1) std::cout << "Montag"; + else if(weekday==2) std::cout << "Dienstag"; + else if(weekday==3) std::cout << "Mittwoch"; + else if(weekday==4) std::cout << "Donnerstag"; + else if(weekday==5) std::cout << "Freitag"; + else std::cout << "Samstag"; getch(); return(0);