Last active
December 13, 2023 23:16
-
-
Save mshafae/8bde313d4a8d491c0229ed30fdad0bc7 to your computer and use it in GitHub Desktop.
if-else if-else example
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
// Gist https://gist.github.com/8bde313d4a8d491c0229ed30fdad0bc7 | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
int main(int argc, char const* argv[]) { | |
std::vector<std::string> command_line_arguments{argv, argv + argc}; | |
if (command_line_arguments.size() < 2) { | |
std::cout << "Please enter a day on the command line.\n"; | |
std::cout << "For example, Tuesday.\n"; | |
return 1; | |
} | |
std::string day{"blah"}; | |
try { | |
day = command_line_arguments.at(1); | |
} catch (std::exception const& e) { | |
std::cout << "There was a problem retrieving the command line argument.\n"; | |
return 1; | |
} | |
if (day == "Monday") { | |
std::cout << "Manic Monday!\n"; | |
} else if (day == "Wednesday") { | |
std::cout << "Half-way to the end of the week.\n"; | |
} else if (day > "Thursday") { | |
std::cout << "Is it Taco Tuesday?\n"; | |
} else if (day == "Friday" && day == "Saturday") { | |
std::cout << "Will I ever see Friday and Saturday?\n"; | |
} else if (day == "Friday" || day == "Saturday") { | |
std::cout << "TGIF or TGIS!\n"; | |
} else if (day == "Sunday" || day == "Monday") { | |
std::cout << "Finally a day of rest or is it Monday?\n"; | |
} else { | |
std::cout << "Nothing special about today.\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment