Age Calculator

WARNING THERE'S A PROBLEM FOR CHILDREN UNDER THE AGE OF 1!

#include <iostream>
using namespace std;
int main()
{
int cday, cmonth, cyear, bday, bmonth, byear, a, b, c;
cout << "Please enter your birthday. The format is Date/Month/Year. Please enter the date: ";
date1:
cin >> bday;
if (bday>31 || bday<=0){
    cout << "Impossible date. Please try again. \n";
    goto date1;
}
month1:
cout << "Now enter your month of birth: ";
cin >> bmonth;
if(bmonth>12 || bmonth <=0){
    cout << "Impossible month. Please trt again. \n";
    goto month1;
}
cout << "Now enter the year please: ";
cin >> byear;
cout << "Thank you! Now lets start on the current date.";
date2:
cout << "Please enter the current date: ";
cin >> cday;
if(cday>31 || cday<=0){
    cout << "Impossible dare, please try again. \n";
    goto date2;
}
month2:
cout << "Please enter the current month: ";
cin >> cmonth;
if(cmonth>12 || cmonth <=0){
    cout << "Impossible month, please try again. \n";
    goto month2;
}
cout << "Please enter the current year: ";
cin >> cyear;
a=cday-bday;
if(bmonth>cmonth){
    b=(12-bmonth)+cmonth;
    }else if(cmonth>bmonth){
    b=12-bmonth;
    }else{
        b=0;
        }
    c=cyear-byear;
    if(a<0){
    a=a*(-1);
    {
    if(b<0){
    b=b*(-1);
    }
    if(c<0){
    cout << "Good Luck with your birth!\n";
    }else if(c<1 && c>=0){

    if(a==0 && b==0){
    cout << "Your age is: " << a << " day " << b << " month old. \n";
    }else if(a==0){
    cout << "You are: " << a << " day " << b << " months old. \n";
    }else if(b==0){
    cout << "You are: " << a << " days " << b << " month old. \n";
    }else{
    cout << "You are: " << a << " days " << b << " months old. \n";
    }
    }else if (c>1 && c<100){
    if(a== 0 && b==0){
    cout << "You are: " << a << " day " << b << " month " << c << " years old. \n";
    }else if(a==0){
    cout << "You are: " << a << " day " << b << " months " << c << " years old. \n";
    }else if(b==0){
    cout << "You are: " << a << " days " << b << " month " << c << " years old. \n";
    }else{
    cout << "You are: " << a << " days " << b << " months " << c << " years old. \n";
    }
    }else if(c>100){
    cout << "Congratulations you are over 100 years old!\n";
    if (a==0 && b==0){
    cout << "You are exactly " << c << " years old!\n";
    }else if(a==0){
    cout << "Your age is: " << a << " day " << b << " months " << c << " years.\n";
    }else if(b==0){
    cout << "Your age is: " << a << " days " << b << " month " << c << " years.\n";
    }else{
    cout << "Your age is: " << a << " days " << b << " months " << c << " years. \n";
    }
}
return 0;
}

Comments

  1. yeah i think the reason it doesnt work for those under 1 is this part
    if(a<0){
    a=a*(-1);
    {
    if(b<0){
    b=b*(-1);
    not sure tho.

    ReplyDelete

Post a Comment