Hello, Thank for the help in past. I have completed the drill/test from the book. It work beautiful on executed. But I would like for you guys to tell me if there is anything I need to change or improve. Such as correctly way to write or clean up the line. However this practice I did is from 3 chapter of Bjarne Stroustrup book. I only type there what I learned from the 3 chapters.
#include "Std_lib_facilities.h"
int main()
{
cout << "Hello! Please type your first name.\n";
string first_name;
cin >> first_name;
cout << "\n";
cout << "Hi " << first_name <<"\n";
cout << "\n";
cout << "Please enter first name you want to write to.\n";
cin >> first_name;
cout << "\n";
cout << "Dear " << first_name << "," << "\n";
cout << "\n";
cout << "\n";
cout << "How are you? What have you been doing these day?\n";
cout << "\n";
cout << "Is there any other friend you would like to write?\n";
cout << "\n";
string friend_name;
cin >> friend_name;
cout << "\n";
cout << "Have you seen " << friend_name << "?" <<"\n";
cout << "\n";
cout << "Enter m if your friend is male, enter f if your friend is female.\n";
char friend_sex;
cin >> friend_sex;
if(friend_sex =='m')
cout << "If you see " << friend_name << " please ask him to call me.\n";
if(friend_sex =='f')
cout << "if you see " << friend_name << " please ask her to call me.\n";
cout << "\n";
cout << "What's your age?\n";
int age;
cin >> age;
cout << "I heard you just had a birthday and you are " << age << " year old\n";
if(age <= 0)simple_error("You are kidding");
cout << "\n";
if(age < 12)
cout << "Next year you will be " << age+1 << "\n";
if(age == 17)
cout << "Next year you will be able to vote.";
if(age >= 70)
cout << "I hope you are enjoying retirement.";
}
edited, fixed the mistake you gave. Thanks It look cleaner and clearly now.
Lines 12,24,67,70: You have extraneous pairs of {}. They do no harm, but do tend to imply to the reader that they are a conditional block of some sort (which they are not).
Line 7,15: first_name is declared twice. This is not currently causing an error because the second declaration is in a nested scope. If you're using these variables for different purposes (your name, first friend name), they should have different variable names.