Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

My C++ Source Code: Age Calculator

thirdreich123

Recruit
Basic Member
Messages
14
Reaction score
1
Points
18
#include <iostream>
#include <cstdlib>
using namespace std;

int main(){

int currentMonth , currentYear , yourAge, yourMonth, wantYear, wantMonth;
int yourYear;
char n[5];
int newMonth, newYear, newAge;
string M;

cout << " enter the current year : ";
cin >> n ;
while(isalpha(n[0])){
cout << " invalid year !! enter again : ";
cin>>n;
}
currentYear = atoi(n);
cout << currentYear;


cout << "\n enter the current month in numbers( 1 - 12 ) : ";
cin >> n;
while(isalpha(n[0])){
cout << " invalid year !! enter again : ";
cin>>n;
}
currentMonth = atoi(n);
cout<<currentMonth;


while(currentMonth > 12 || currentMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
currentMonth = atoi(n);

cout << "\n enter your current age : ";
cin >> n;
while(isalpha(n[0])){
cout << " invalid age !! enter again : ";
cin>>n;
}
yourAge = atoi(n);

cout << "\n enter the month in which you where born : ( 1 - 12 ) : ";
cin >> n;
while(isalpha(n[0])){
cout << " invalid month !! enter again : ";
cin>>n;
}
yourMonth = atoi(n);

while(currentMonth > 12 || currentMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
yourMonth = atoi(n);

cout << "\n enter the year how you wish to know your age : ";
cin >> n;
while(isalpha(n[0])){
cout << " invalid year !! enter again : ";
cin>>n;
}
wantYear = atoi(n);

cout << "\n enter the month how wish to know your age : ";
cin >> n;
while(isalpha(n[0])){
cout << " invalid month !! enter again : ";
cin>>n;
}
wantMonth = atoi(n);

while(wantMonth > 12 || wantMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
wantMonth = atoi(n);

yourYear = currentYear - yourAge ;
cout<<" ----------------------------------------------------------- "<<endl;
cout << "\n your birth month and year is: "<<yourMonth<< " / "<<yourYear<<" and your age is "<<yourAge<<endl;
newAge = yourAge + (wantYear - currentYear);

if(newAge > 149){
cout << "\n sorry but your probably be dead by this year "<<wantYear;
}
else{
if(yourMonth > wantMonth)
newMonth = (12 - yourMonth ) + wantMonth;
else
newMonth = wantMonth - yourMonth;
if(newMonth > 1)
M = "months";
else
M = "month";

cout << "\n your age in "<<wantMonth<<" / "<<wantYear<<" is : "<<newAge<<" and "<<newMonth<<" "<<M;
}
cout<<"\n\n\n";
return 0;
}
 
Back
Top Bottom