months in numbers to letters

How do i make the range of months from 1-12? How do i make the days of the months so it can be valid. For example 2 29 2003 is invalid because 2003 is not a leap year.

I have to use string variable to convert the month in numbers to letters. Im trying to get my program to look like this.

Sample Run 1:
Enter numeric values for month, day and year of the first date> 10 10 2005
October 10, 2005 is a date in a non-leap year.

Sample Run 2:
Enter numeric values for month, day and year of the second date> 1 10 1582
01/10/1582 is not a valid date.

Sample Run 3:
Enter numeric values for month, day and year of the first date> 2 29 2004
February 29, 2004 is a date in a leap year.


this is what i got so far:
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
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstring>

using namespace std;

int main()

{
   int month, day, year;

   //Sample 1
   cout << "Sample Run 1:" << endl;
   cout << "Enter numeric values for month, day and year of the first date> ";
   cin >> month >> day >> year;

   if(year <= 1582)
     cout << month << " " << day << " " << year << " is not a valid date.";
   else if(month 
   else if(year % 4 == 0)
     cout << month << " " << day << " " << year << " is a date in a leap year.";
   else if(year % 4 >0) 
     cout << month << " " << day << " " << year << " is a date in a non-leap year." << endl;
   cout << endl;

   
   return 0;
 
}
Write a function that tells you whether or not a given year is a leap year.
1
2
3
4
5
6
7
bool is_leap_year( int year )
{
    if (...)
        return true;
    else
        return false;
}

To calculate whether or not a year is a leap year, use the formula found here:
http://en.wikipedia.org/wiki/Leap_year#Algorithm

Now you can know whether or not February can have 29 days when given a specific year.

Hope this helps.
thank you!
1
2
3
4
5
6
7
8
9
10
   if (valid_month && valid_day && valid_year)
   {
      if (leapYear)
         cout << monthInWords << " " << day << ", " << year << " is a date in a leap year.";
      else
         cout << monthInWords << " " << day << ", " << year << " is a date in a non-leap year.";
   }
   else
      cout << month << "/" << day << "/" << year << " is not a valid date.";
              


how do i print the zeros in front of single numbers?

Sample Run 2:
Enter numeric values for month, day and year of the second date> 1 10 1582
01/10/1582 is not a valid date.


would i use the setprecison or setwidth?
Last edited on
Topic archived. No new replies allowed.