Days until next birthday

I am having trouble writing a program that computes the number of days until the user's next birthday. Is anyone able to help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

#include <iostream>
using namespace std;

void getDate(int& current_day, int& current_month, int& current_year);
void birthday(int& birth_day, int& birth_month);
bool isLeapYear(int current_year);
int daysInYear(int current_year);
int daysInMonth(int current_month, int current_year);
int computeDaysLeftToBirthday(int birth_day, int birth_month, int current_day, int current_month, int current_year);

int main() {

	int current_day;
	int current_month;
	int current_year;
	int birth_day;
	int birth_month;
	int birth_year;
	char repeat;

	do {
		getDate(current_day, current_month, current_year);
		birthday(birth_day, birth_month);
		computeDaysLeftToBirthday(birth_day, birth_month, current_day, current_month, current_year);

		cout << endl;
		cout << "Would you like to perform another calculation? (Y/N) ";
		cin >> repeat;
		cout << endl;

	} while (repeat == 'Y' || repeat == 'y');

	return 0;
}

void getDate(int& current_day, int& current_month, int& current_year)
{
	cout << "Please enter the current day: ";
	cin >> current_day;
	cout << "Please enter the current month (1-12): ";
	cin >> current_month;
	cout << "Please enter the current year: ";
	cin >> current_year;
}

void birthday(int& birth_day, int& birth_month)
{
	cout << "Please enter the day of your birthday: ";
	cin >> birth_day;
	cout << "Please enter the month of your birthday: ";
	cin >> birth_month;
}

bool isLeapYear(int current_year)
{
	if (current_year % 400 == 0 || (current_year % 4 == 0 && current_year % 100 != 0))
		return true;
	else
		return false;
}

int daysInYear(int current_year)
{
	int days_year = 0;
	if (isLeapYear(current_year) == true){
		days_year = 366;
	}
	else {
		days_year = 365;
	}
	return days_year;
}

int daysInMonth(int current_month, int current_year)
{
	int days_month;
	if (current_month == 4 || current_month == 6 || current_month == 9 || current_month == 11) {
		days_month = 30;
	}
	else if (current_month == 2) {
		if (isLeapYear(current_year) == true){
			days_month = 29;
		}
		else {
			days_month = 28;
		}

	}
	else {
		days_month = 31;
	}
	return days_month;
	}


int computeDaysLeftToBirthday(int birth_day, int birth_month, int current_day, int current_month, int current_year)
{
	int result = 0;

	result =  
You have the basic pieces you need.

You need to compute the serial day number (which day within the year) of both the current day and the birthday. Then take the difference between the two numbers. Don't forget that the difference can be negative, which means the birthday has passed and won't occur again until next year.
Topic archived. No new replies allowed.