Skip to content

Commit

Permalink
Chapter 3. Tasks and Exercise 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grandmother committed Mar 24, 2016
1 parent 91b5ea6 commit e4c0c33
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
14 changes: 14 additions & 0 deletions chapter 3/exercise_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>

int main()
{
std::cout << "Enter a distance in miles: ";

double miles = 0;
std::cin >> miles;
std::cout << miles << " miles is " << miles*1.609 << " kilomiters.\n";

std::cin.get();
std::cin.get();
return 0;
}
61 changes: 61 additions & 0 deletions chapter 3/tasks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <iostream>

inline void simple_error(std::string s)
{
std::cerr << "error: " << s << '\n';
std::cin.get();
exit(1);
}

int main()
{
std::string username, addressee, frnd;
char frnd_sex {' '};
int addr_age = 0;

std::cout << "Enter your name please: ";
std::cin >> username;
std::cout << "Enter the name of addressee and his age please: ";
std::cin >> addressee >> addr_age;

if ( addr_age < 0 || addr_age > 110 )
{
simple_error("Are you kidding me?\nYes, you kidding me!!\nBye!");
}

std::cout << "Enter your friend name and sex: ";
std::cin >> frnd >> frnd_sex;

std::cout << "\nHello, dear " << addressee << "!\n"
<< "\nNice to write you again.\n";
if (frnd_sex == 'm')
{
std::cout << "Today I have met our old friend, " << frnd << ". He was create a new electrocar in his workshop whith his new friends.\n"
<< "I can ask him to call you when we meet again.\n";
}
else
{
std::cout << "Today I have met our old friend, " << frnd << ". She was create a new electrocar in her workshop whith her new friends.\n"
<< "I can ask her to call you when we meet again.\n";
}
std::cout << "I heard you have selebrated your birthday and now you are " << addr_age << " years old.";
if ( addr_age == 17 )
{
std::cout << " So you can participate in polls next year!!\n";
}
else if ( addr_age < 12 )
{
std::cout << " And you would be " << addr_age+1 << " years old next year.";
}
else if ( addr_age > 70 )
{
std::cout << " I hope you wouldn't bored on pension.";
}

std::cout << "\n\nBest Regards\n"
<< "____________________\n"
<< "____________________\n"
<< username << '\n';

return 0;
}
6 changes: 3 additions & 3 deletions chapter 3/unsafe_types_cast_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ int main()
double d = 0;
while (std::cin >> d)
{
int i = d;
char c = i;
int i2 = c;
int i {d};
char c {i};
int i2 {c};

std::cout << "d == " << d << '\n'
<< "i == " << i << '\n'
Expand Down

0 comments on commit e4c0c33

Please sign in to comment.