-
Notifications
You must be signed in to change notification settings - Fork 165
refactor(ex4.cpp): improved readability and efficiency #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Giuseppe-Tornello
wants to merge
11
commits into
UNICT-Quality-Development:main
Choose a base branch
from
Giuseppe-Tornello:Ex4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c403c47
refactor: replacing if statement with switch
griboni 648684e
Fix:indentation
griboni eac0628
Revert "Fix:indentation"
griboni 2f81402
Revert "refactor: replacing if statement with switch"
griboni a2b20f0
refactor: replacing deprecated C I/O functions
griboni e312c6b
refactor: improve switch case handling
griboni 0f521df
refactor: Improved switch readability
griboni 0788ce5
refactor: replaced deprecated C I/O functions pt2
griboni 75fb69e
refactor: replaced deprecated C I/O functions pt3
griboni 2a96900
refactor: moved switch to a different function
griboni a8b6113
chore(printMonth): set const parameter in funcion
griboni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,60 @@ | ||
| /* Surprise me. */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <iostream> | ||
| using namespace std; | ||
|
|
||
| void printMonth(int& month); | ||
|
|
||
| enum months{ | ||
| January=1, | ||
| February, | ||
| March, | ||
| April, | ||
| May, | ||
| June, | ||
| July, | ||
| August, | ||
| September, | ||
| October, | ||
| November, | ||
| December | ||
| }; | ||
|
|
||
| void printMonth(const int& month){ | ||
| switch (month){ | ||
| case January: | ||
| case March: | ||
| case May: | ||
| case July: | ||
| case August: | ||
| case October: | ||
| case December: | ||
| cout << "31 days" << endl; | ||
| break; | ||
| case February: | ||
| cout << "28/29 days" << endl; | ||
| break; | ||
| case April: | ||
| case June: | ||
| case September: | ||
| case November: | ||
| cout << "30 days" << endl; | ||
| break; | ||
| default: | ||
| cout << "Invalid input! Please enter month number between 1-12" << endl; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| int month; | ||
|
|
||
| /* Input month number from user */ | ||
| printf("Enter month number(1-12): "); | ||
| scanf("%d", &month); | ||
|
|
||
| switch (month) | ||
| { | ||
| case 1: | ||
| printf("31 days"); | ||
| break; | ||
| case 2: | ||
| printf("28/29 days"); | ||
| break; | ||
| case 3: | ||
| printf("31 days"); | ||
| break; | ||
| case 4: | ||
| printf("30 days"); | ||
| break; | ||
| case 5: | ||
| printf("31 days"); | ||
| break; | ||
| case 6: | ||
| printf("30 days"); | ||
| break; | ||
| case 7: | ||
| printf("31 days"); | ||
| break; | ||
| case 8: | ||
| printf("31 days"); | ||
| break; | ||
| case 9: | ||
| printf("30 days"); | ||
| break; | ||
| case 10: | ||
| printf("31 days"); | ||
| break; | ||
| case 11: | ||
| printf("30 days"); | ||
| break; | ||
| case 12: | ||
| printf("31 days"); | ||
| break; | ||
| default: | ||
| printf("Invalid input! Please enter month number between 1-12"); | ||
| } | ||
| cout << "Enter month number(1-12): " << endl; | ||
| cin >> month; | ||
|
|
||
| printMonth(month); | ||
|
|
||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.