Sep 9, 2012 at 5:47pm UTC
Hello, if you can help, I would like to know how to make this program identify a valid birthday, if the date is in the future and check if the person is more than 100 years old.
Another problem I have encountered is when I execute the program it automatically closes even after putting system ("pause"). Here's what I have so far.
/code
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int print_month(int p_month);
bool leapyear(int lpyr) {
return ((lpyr % 4 == 0 && lpyr % 100 != 0) || lpyr % 400 == 0);
}
int main()
{
int month,days,year;
int monthDays,lastDayDec;
int p_days;
cout << "Enter a date in the form of month-day-year: ";
cin >> month >> days >> year;
if ( month < 1 || month > 12 ){
cout << "INVALID: Please try again." << endl;
}
if ( days < 1 || days > 31 ){
cout << "INVALID: Please try again." << endl;
}
if ( leapyear(year) ){
cout << year << " is a leap year." << endl;
}
cout << "You have entered: " << month << "-" << days << "-" << year << endl;
monthDays = print_month(month);
cout << "The monthday is " << monthDays << endl;
}
int print_month(int p_month)
{
int p_days;
p_month = p_month - 1;
switch (p_month){
case 12 :
p_days = p_days + 31;
case 11 :
p_days = p_days + 30;
case 10 :
p_days = p_days + 31;
case 9 :
p_days = p_days + 30;
case 8 :
p_days = p_days + 31;
case 7 :
p_days = p_days + 31;
case 6 :
p_days = p_days + 30;
case 5 :
p_days = p_days + 31;
case 4 :
p_days = p_days + 30;
case 3 :
p_days = p_days + 31;
case 2 :
p_days = p_days + 28;
case 1 :
p_days = p_days + 31;
default :
cout << "Invalid Value!\a";
}
return p_days;
}
/code
Sep 9, 2012 at 6:26pm UTC
I do not see the call of system in your program.