i am in a beginners c++ class and we are on our second program. I have been working on it for two weeks (remember I'm brand spanking new at all this) and my program compiles but does not have the desired end result.
Here are the directions:
Your program should consist of only one function, the main function. When
your program begins, the user is prompted to enter integer values representing
the month, day, and year, in that order. You do not need to validate the
date. The user’s entry is assumed to be a valid date. Your program should
then display [day-of-the-week-in-words], [month-in-words] [day], [year] and
indicate whether this date occurs in a leap year. Use a boolean variable
as a flag to indicate whether the year is a leap year or not.(The calendar
generator at
http://www.timeanddate.com/calendar may be helpful to
you in verifying the correctness of your program.)
My program won't put out the month and day of the week in words, but other then that it works..here is my program let me know whats wrong:
#include <iostream>
using namespace std;
int main()
{
int month, day, year;
cout<<"Enter numeric values for month, day and year of a date>";
cin>>month>>day>>year;
bool yearLeap, monthWord, dayWord;
yearLeap = year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
if(month == 1)
monthWord = "January ";
else if(month == 2)
monthWord = "February ";
else if(month == 3)
monthWord = "March ";
else if(month == 4)
monthWord = "April ";
else if(month == 5)
monthWord = "May ";
else if(month == 6)
monthWord = "June ";
else if(month == 7)
monthWord = "July ";
else if(month == 8)
monthWord = "August ";
else if(month == 9)
monthWord = "September ";
else if(month == 10)
monthWord = "October ";
else if(month == 11)
monthWord = "November ";
else if(month == 12)
monthWord = "December ";
int u,v,w,x,y,century;
century = year / 100;
u = 2 * (3-(century%4));
v = century%100;
w = v/4;
if(month == 1)
{
if(month == yearLeap)
{
x = 6;
}
else
{
x = 0;
}
}
else if(month == 2)
{
if(month == yearLeap)
{
x = 2;
}
else
{
x = 3;
}
}
else if(month == 3)
{
x = 3;
}
else if(month == 4)
{
x = 6;
}
else if(month == 5)
{
x = 1;
}
else if(month == 6)
{
x = 4;
}
else if(month == 7)
{
x = 6;
}
else if(month == 8)
{
x = 2;
}
else if(month == 9)
{
x = 5;
}
else if(month == 10)
{
x = 0;
}
else if(month == 11)
{
x = 3;
}
else if(month == 12)
{
x = 5;
}
y = u+v+w+x+day;
dayWord = y%7;
if(dayWord == 0)
dayWord = "Sunday ";
if(dayWord == 1)
dayWord = "Monday ";
if(dayWord == 2)
dayWord = "Tuesday ";
if(dayWord == 3)
dayWord = "Wednesday ";
if(dayWord == 4)
dayWord = "Thrusday ";
if(dayWord == 5)
dayWord = "Friday ";
if(dayWord == 6)
dayWord = "Saturday ";
if(yearLeap == true)
{
cout<<monthWord<<dayWord<<", "<<year<<" occurred in a leap year.";
}
else
{
cout<<monthWord<<dayWord<<", "<<year<<" occurred in a non-leap year.";
}
return 0;
}