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.
Submitted On | |
By | Brian Griffin |
Level | Beginner |
User Rating | 4.0 (24 globes from 6 users) |
Compatibility | C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++ |
Category | Algorithms |
World | C / C++ |
Archive File |
/*************************************
* Age Calculation Algorithm *
* By: Brian Griffin *
*************************************/
#include
//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;
}