From 94c035c0ccf11b419b8ba642c745462fb477ea9c Mon Sep 17 00:00:00 2001 From: kjozwiak Date: Sat, 5 Dec 2015 17:50:14 -0500 Subject: [PATCH] moar tutorials --- learnCPP/learncpp.com/Chapter2/chars.cpp | 20 ++++++++++++++++++++ learnCPP/learncpp.com/Chapter2/const.cpp | 20 ++++++++++++++++++++ learnCPP/learncpp.com/Chapter2/constants.h | 8 ++++++++ 3 files changed, 48 insertions(+) create mode 100644 learnCPP/learncpp.com/Chapter2/chars.cpp create mode 100644 learnCPP/learncpp.com/Chapter2/const.cpp create mode 100644 learnCPP/learncpp.com/Chapter2/constants.h diff --git a/learnCPP/learncpp.com/Chapter2/chars.cpp b/learnCPP/learncpp.com/Chapter2/chars.cpp new file mode 100644 index 0000000..82b83b9 --- /dev/null +++ b/learnCPP/learncpp.com/Chapter2/chars.cpp @@ -0,0 +1,20 @@ +#include + +int main() +{ + std::cout << "Please enter \"y\" or \"n\": "; + char choice{}; + std::cin >> choice; + if (static_cast(choice) == 121) { + std::cout << "You've selected Yes!!" << "\n"; + } else if (static_cast(choice) == 110) { + std::cout << "You've selected No!!" << "\n"; + } else { + std::cout << "Damit.. You didn't follow directions..!" << "\n"; + } + std::cout << "Please insert any letter from alphabet: "; + char userInput{}; + std::cin >> userInput; + std::cout << "the letter " << userInput << " translates to " << static_cast(userInput) << " in ASCII!" << "\n"; + return 0; +} \ No newline at end of file diff --git a/learnCPP/learncpp.com/Chapter2/const.cpp b/learnCPP/learncpp.com/Chapter2/const.cpp new file mode 100644 index 0000000..f494428 --- /dev/null +++ b/learnCPP/learncpp.com/Chapter2/const.cpp @@ -0,0 +1,20 @@ +#include +#include "constants.h" + +int main() +{ + constexpr int16_t myBirthday{7}; // constant resolved during compile-time + std::cout << "My birthday is on the: " << myBirthday << "th!" << "\n"; + std::cout << "What day is your birthday?: "; + int16_t x{}; + std::cin >> x; + const int16_t z{x}; // constant resolved during run-time + std::cout << "My birthday is on the: " << z << "th!" << "\n"; + if (z == myBirthday) { + std::cout << "You have the same birthday as me!! \n"; + } else { + std::cout << "You're definitely not as cool as me...\n"; + } + std::cout << "Sonja's birthday is on the " << constants::sonjaBirthday << "\n"; + return 0; +} \ No newline at end of file diff --git a/learnCPP/learncpp.com/Chapter2/constants.h b/learnCPP/learncpp.com/Chapter2/constants.h new file mode 100644 index 0000000..c6db5e2 --- /dev/null +++ b/learnCPP/learncpp.com/Chapter2/constants.h @@ -0,0 +1,8 @@ +#ifndef CONSTANTS_H +#define CONSTANTS_H + +namespace constants { + const double pi(3.14159); + const int16_t sonjaBirthday{25}; +} +#endif \ No newline at end of file