From a9dad21f83fc0ccbf31893b89f61c3c34ee7e94b Mon Sep 17 00:00:00 2001 From: Gabriele Privitera Date: Wed, 18 Oct 2023 20:51:10 +0200 Subject: [PATCH 1/2] fix --- exercises/ex2.cpp | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/exercises/ex2.cpp b/exercises/ex2.cpp index 9e8cd8e..b482d48 100644 --- a/exercises/ex2.cpp +++ b/exercises/ex2.cpp @@ -9,41 +9,16 @@ using namespace std; int main() { - int week; + int day; + cout << "Enter week number(1-7): "; + cin >> day; - cout << "Enter week number(1-7): " << endl; - cin >> week; + string week[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; - if (week == 1) - { - cout << "Monday" << endl; + if(day - 1 >= 0 && day - 1 <= 6){ + cout << week[day - 1] << endl; } - else if (week == 2) - { - cout << "Tuesday" << endl; - } - else if (week == 3) - { - cout << "Wednesday" << endl; - } - else if (week == 4) - { - cout << "Thursday" << endl; - } - else if (week == 5) - { - cout << "Friday" << endl; - } - else if (week == 6) - { - cout << "Saturday" << endl; - } - else if (week == 7) - { - cout << "Sunday" << endl; - } - else - { + else{ cout << "Invalid input! Please enter week number between 1-7." << endl; } From 5db742aa5f766cb47dc859d9613e1cb0c6a8b442 Mon Sep 17 00:00:00 2001 From: Gabriele Privitera <102214867+PriviteraGabriele@users.noreply.github.com> Date: Thu, 19 Oct 2023 08:28:50 +0200 Subject: [PATCH 2/2] fix: EXIT_SUCCES constant defined --- exercises/ex2.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/ex2.cpp b/exercises/ex2.cpp index b482d48..c3116d9 100644 --- a/exercises/ex2.cpp +++ b/exercises/ex2.cpp @@ -4,6 +4,8 @@ Hint: arr[3] = "Thursday"; */ +#define EXIT_SUCCESS 0 + #include using namespace std; @@ -22,5 +24,5 @@ int main() cout << "Invalid input! Please enter week number between 1-7." << endl; } - return 0; -} \ No newline at end of file + return EXIT_SUCCESS; +}