Skip to content

Commit

Permalink
moar tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
kjozwiak committed Dec 5, 2015
1 parent fb5ff5f commit 94c035c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions learnCPP/learncpp.com/Chapter2/chars.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>

int main()
{
std::cout << "Please enter \"y\" or \"n\": ";
char choice{};
std::cin >> choice;
if (static_cast<int16_t>(choice) == 121) {
std::cout << "You've selected Yes!!" << "\n";
} else if (static_cast<int16_t>(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<int16_t>(userInput) << " in ASCII!" << "\n";
return 0;
}
20 changes: 20 additions & 0 deletions learnCPP/learncpp.com/Chapter2/const.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#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;
}
8 changes: 8 additions & 0 deletions learnCPP/learncpp.com/Chapter2/constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H

namespace constants {
const double pi(3.14159);
const int16_t sonjaBirthday{25};
}
#endif

0 comments on commit 94c035c

Please sign in to comment.