Age Algorithm - GREAT for Beginners!

Submitted on: 1/3/2015 8:54:00 PM
By: Brian Griffin (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 2668
     This is my first C++ algorithm as well as my first submission to PSCode. It is definitely great for beginners. It has basic I/O and practices doing math in C++. You enter your age, the current year, and a year in the future and it tells you how old you will be in that year.

* Age Calculation Algorithm *
* By: Brian Griffin*
  //NOTE: the above line is supposed to say iostream.h inside <>'s following the include. It was interpreted as HTML so it disappeared.

void main(){
int age, newYear, currentYear, newAge, next;

cout << "Age Calculation Algorithm" << endl;
cout << "By: Brian Griffin" << endl;
cout << "--------------------------" << endl;
cout << "Age: ";
cin >> age;
cout << "Current Year: ";
cin >> currentYear;
cout << "Year to find age in: ";
cin >> newYear;
cout << "--------------------------" << endl;

newAge = (newYear - currentYear) + age;
cout << "You will be " << newAge << " in the year " << newYear << "." << endl;
cin >> next;

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.