I am independently learning C++ using the Second Edition of "Programming Principles and Practice Using C++" by Bjarne Stroustrup. I have reached the end of chapter 3 and I am completing the drill. It involves writing a program that produces a "simple form letter, based on user input".
The task for step 5 of this drill is as follows (quoted word for word):
Prompt the user to enter the age of the recipient and assign it to an int variable age. Have your program write "I hear you just had a birthday and you are age years old." If age is 0 or less or 110 or more, call simple_error("you're kidding!") using simple_error() from std_lib_facilities.h.
See my syntax below:
cout << "\n\nEnter the age of " << first_name << ":\n";
int age;
cin >> age;
cout << " I heared you just had a birthday and you are " << age << " years old. \n\n";
if (age <= 0 || age >= 110)
simple_error("you're kidding!");
Is my use of the 'if' statement, it's conditions and simple_error() correct as per the instructions of step 5?
It seems strange because the purpose of the program is to write a letter and simple error("you're kidding!") outputs "error: you're kidding!" in the letter... should I take this so literally?
I really appreciate your time and advice.
Aucun commentaire:
Enregistrer un commentaire