-
April 3rd, 2013, 07:40 PM
#1
New Programmer Trying to Output the Day of the Week
Hi guys, I'm just starting coding and having a heck of a time trying to figure out how to make this application. It's pretty simple and I just want it to input a date, then output a day of the week. If any of you could just give me a few pointers as to where I'm going wrong, I'd greatly appreciate it!
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int startday = 0, sm = 1, sd = 1, sy = 2000, cm = 0, cd = 0, cy = 0;
cout << "Please enter the current month, day, and year: ";
cin >> cm >> cd >> cy; int curyear = cy, curmonth = cm, curday = cd;
//Months added
while (curmonth >= 1)
{
if (curmonth == 1 || 3 || 5 || 7 || 8 || 10 || 12) //March, May, July, August, September, December
{
startday = startday + 31;
}
else if (curmonth == 2)
{
//LEAP YEAR HERE, YOU!
if ((curyear % 4 == 0) && ((curyear % 400 == 0) || (curyear / 4 != 100)))
{
startday = startday + 29;
}
else
{
startday = startday + 28;
}
}
else if (curmonth == 4 || 6 || 9 || 11)
{
startday = startday + 30;
}
curmonth--;
}
//Years Added
for (; cy < sy; cy++)
{
startday = startday + (365 * cy) + cd;
}
int dayname = (startday - 1) % 7;
if (dayname == 6)
cout << cm << " " << cd << " " << curyear << " was a Thursday";
else if (dayname == 0)
cout << cm << " " << cd << " " << curyear << " was a Friday";
else if (dayname == 1)
cout << cm << " " << cd << " " << curyear << " was a Saturday";
else if (dayname == 2)
cout << cm << " " << cd << " " << curyear << " was a Sunday";
else if (dayname == 3)
cout << cm << " " << cd << " " << curyear << " was a Monday";
else if (dayname == 4)
cout << cm << " " << cd << " " << curyear << " was a Tuesday";
else cout << cm << " " << cd << " " << curyear << " was a Wednesday";
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|