| Visual C++ | PAGE (4 of 6) |
Now that you have created a Project, you can add source code to it.
To do so, go to the Project menu, select Add to Project, then New
You should see the following:
Now in the edit window that just appeared, type in the following code:
#include <iostream.h>
int main() //Find the Day of the Week for a Date
{
int mon, day, year;
cout << "Enter a date for which you wish to know" << endl;
cout << "the day of the week (MM DD YYYY)? ";
cin << month >> day >> year;
if (year < 1752)
cout << "Only Gregorian dates accepted, sorry " << endl;
else {
if (month < 3) { //Jan & Feb = 13 & 14 preceding year
month += 12;
year -= 1;
{ // end if
weekDay = (day + 2*month + 3*(month+1)/5 + year +
year/4 - year/100 + year/400 + 1) % 7;
if (month > 12) { //reset Jan & Feb
month -= 12;
year += 1 ;
} // end if
cout << month << "/" < day << "/" << year << " falls on ";
switch (weekday)
{
case 0: cout << "Sunday" << endl; break;
case 1: cout << "Monday" << endl; break;
case 2: cout << "Tuesday" << endl; break;
case 3: cout << "Wednesday" << endl; break;
case 4: cout << "Thursday" << endl; break;
case 5: cout << "Friday" << endl; break;
case 6: cout << "Saturday" << endl; break;
} // end switch
} // end else
return 0;
} // end main
Now you are ready to Build your project.
| © CS Dept Va Tech, 1999. | All rights reserved. |