0

It's a code to calculate age from today's current date.
I know I'll have to use #include <ctime>
But I have no idea what I would use for the rest.

Here's my code:

package practicing;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class FindRelativeAge {

    private static Calendar calendar = Calendar.getInstance();
    private static String birthDate = "";
    private static String[] myArray = null;
    private static int birthDay = 0;
    private static int birthMonth = 0;
    private static int birthYear = 0;
    private static Scanner wiz = new Scanner(System.in);

    public static void enterYourDumbAssBirthday() {
        System.out.print("What is your birthday (e.g. 4/15/1994) -> ");
        birthDate = wiz.nextLine();
        myArray = birthDate.split("/");
        birthDay = Integer.parseInt(myArray[1].trim());
        birthMonth = Integer.parseInt(myArray[0].trim());
        birthYear = Integer.parseInt(myArray[2].trim());

    }

    public static void findWhenYourNextDumbAssBirthdayIs() {
        int currentMonth =  calendar.get(Calendar.MONTH) + 1;
        int currentDate = calendar.get(Calendar.DATE);
        //int currentYear =  calendar.get(Calendar.YEAR);
        int temp = 12 - currentMonth + birthMonth;
        int temp2 = currentDate -birthDay;

        System.out.println("Your birthday is " + temp + " months & " + temp2 + " days away");
//      System.out.println("You were born -> " + birthDate);
//      System.out.println("Your next birthday is -> " + monthDifference + " months away");
//      System.out.println("                      -> " + dayDifference + " days away");
//      System.out.println("                      -> " + yearDifference + " years away");
//      
    }

    public static void main(String[] args) {
        enterYourDumbAssBirthday();
        findWhenYourNextDumbAssBirthdayIs();
    }

}
2
Contributors
1
Reply
17
Views
3 Years
Discussion Span
Last Post by vijayan121
0
#include <iostream>
#include <ctime>

namespace bday_utils {
    namespace {
        int bday = 0;
        int bmonth = 0;
        int byear = 0;

        void get_dumbass_birthday() {
            std::cout << "What is your bday (e.g. 4/15/1994) -> " ;
            char slash ;
            std::cin >> bmonth >> slash >> bday >> slash >> byear ;
        }

        void show_next_dumbass_birthday() {
            const auto now = std::time(nullptr) ;
            const auto& tm = *std::localtime( &now ) ;
            const int temp = 11 - tm.tm_mon + bmonth ;
            const int temp2 = tm.tm_mday - bday;
            std::cout << "Your bday is " << temp << " months & " << temp2 << " days away\n" ;
        }
    }
}

int main()
{
    bday_utils::get_dumbass_birthday();
    bday_utils::show_next_dumbass_birthday();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.