diff --git a/exercises/ex2.cpp b/exercises/ex2.cpp index 9e8cd8e..c3116d9 100644 --- a/exercises/ex2.cpp +++ b/exercises/ex2.cpp @@ -4,48 +4,25 @@ Hint: arr[3] = "Thursday"; */ +#define EXIT_SUCCESS 0 + #include 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; - } - 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; + if(day - 1 >= 0 && day - 1 <= 6){ + cout << week[day - 1] << endl; } - else - { + else{ cout << "Invalid input! Please enter week number between 1-7." << endl; } - return 0; -} \ No newline at end of file + return EXIT_SUCCESS; +}