From 6a6cce7342e7284d7fbf845c5feec5440c354368 Mon Sep 17 00:00:00 2001 From: LeottaAlberto Date: Tue, 4 Nov 2025 14:04:06 +0100 Subject: [PATCH 1/3] refactor: improve a swtich-case --- exercises/ex1.cpp | 59 ++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/exercises/ex1.cpp b/exercises/ex1.cpp index 22069589..c5a7fc26 100644 --- a/exercises/ex1.cpp +++ b/exercises/ex1.cpp @@ -10,38 +10,33 @@ int main() /* Input week number from user */ cout << "Enter week number(1-7): " << endl; cin >> week; - - 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 (week){ + 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; + break; } return 0; From 75d9277ad97be62b9764448c9465792554e3097b Mon Sep 17 00:00:00 2001 From: LeottaAlberto Date: Tue, 4 Nov 2025 16:45:57 +0100 Subject: [PATCH 2/3] style: remove whitespaces --- exercises/ex1.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/exercises/ex1.cpp b/exercises/ex1.cpp index c5a7fc26..aec21ca4 100644 --- a/exercises/ex1.cpp +++ b/exercises/ex1.cpp @@ -10,7 +10,6 @@ int main() /* Input week number from user */ cout << "Enter week number(1-7): " << endl; cin >> week; - switch (week){ case 1: cout << "Monday" << endl; @@ -33,7 +32,6 @@ int main() case 7: cout << "Sunday" << endl; break; - default: cout << "Invalid input! Please enter week number between 1-7." << endl; break; From 004c10a7b0c198cb488bf54e95d911d204a55463 Mon Sep 17 00:00:00 2001 From: LeottaAlberto Date: Wed, 5 Nov 2025 18:00:07 +0100 Subject: [PATCH 3/3] refactor: remove unnecessary endl --- exercises/ex1.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/exercises/ex1.cpp b/exercises/ex1.cpp index aec21ca4..95fc519c 100644 --- a/exercises/ex1.cpp +++ b/exercises/ex1.cpp @@ -12,30 +12,32 @@ int main() cin >> week; switch (week){ 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."; break; } - return 0; + cout << endl; + + return EXIT_SUCCESS; } \ No newline at end of file