- 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;
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;
cout<<currentMonth;
while(currentMonth > 12 || currentMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
currentMonth = atoi;
cout << "\n enter your current age : ";
cin >> n;
while(isalpha(n[0])){
cout << " invalid age !! enter again : ";
cin>>n;
}
yourAge = atoi;
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;
while(currentMonth > 12 || currentMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
yourMonth = atoi;
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;
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;
while(wantMonth > 12 || wantMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
wantMonth = atoi;
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;
}
#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;
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;
cout<<currentMonth;
while(currentMonth > 12 || currentMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
currentMonth = atoi;
cout << "\n enter your current age : ";
cin >> n;
while(isalpha(n[0])){
cout << " invalid age !! enter again : ";
cin>>n;
}
yourAge = atoi;
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;
while(currentMonth > 12 || currentMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
yourMonth = atoi;
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;
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;
while(wantMonth > 12 || wantMonth < 0){
cout << " invalid month !! enter again : ";
cin >> n;
}
wantMonth = atoi;
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;
}