From ea576931246d06a5a8b70718afe8badb9c16a432 Mon Sep 17 00:00:00 2001 From: Gabriele Privitera Date: Wed, 18 Oct 2023 20:38:51 +0200 Subject: [PATCH 1/2] fix --- exercises/ex1.cpp | 61 +++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/exercises/ex1.cpp b/exercises/ex1.cpp index 2206958..f346bfd 100644 --- a/exercises/ex1.cpp +++ b/exercises/ex1.cpp @@ -5,43 +5,36 @@ using namespace std; int main() { - int week; + int day; /* Input week number from user */ - cout << "Enter week number(1-7): " << endl; - cin >> week; + cout << "Enter week number(1-7): "; + cin >> day; - if (week == 1) - { - cout << "Monday" << 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 - { - cout << "Invalid input! Please enter week number between 1-7." << endl; + switch (day) { + case 1: + cout << "Monday" << endl; + break; + case 2: + cout << "Tuesday" << endl; + break; + case 3: + cout << "Wednesday" << endl; + break; + case 4: + cout << "Thursday" << endl; + break; + case 5: + cout << "Friday" << endl; + break; + case 6: + cout << "Saturday" << endl; + break; + case 7: + cout << "Sunday" << endl; + break; + default: + cout << "Invalid input! Please enter week number between 1-7." << endl; } return 0; From 96a7aa4bdc5a90ec7759c173ac1313fa1315f887 Mon Sep 17 00:00:00 2001 From: Gabriele Privitera Date: Wed, 18 Oct 2023 20:55:39 +0200 Subject: [PATCH 2/2] fix --- exercises/ex1.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/exercises/ex1.cpp b/exercises/ex1.cpp index f346bfd..44ca47b 100644 --- a/exercises/ex1.cpp +++ b/exercises/ex1.cpp @@ -13,29 +13,30 @@ int main() switch (day) { case 1: - cout << "Monday" << endl; + cout << "Monday"; break; case 2: - cout << "Tuesday" << endl; + cout << "Tuesday"; break; case 3: - cout << "Wednesday" << endl; + cout << "Wednesday"; break; case 4: - cout << "Thursday" << endl; + cout << "Thursday"; break; case 5: - cout << "Friday" << endl; + cout << "Friday"; break; case 6: - cout << "Saturday" << endl; + cout << "Saturday"; break; case 7: - cout << "Sunday" << endl; + cout << "Sunday"; break; default: - cout << "Invalid input! Please enter week number between 1-7." << endl; + cout << "Invalid input! Please enter week number between 1-7."; } + cout << endl; return 0; } \ No newline at end of file