I am producing a program that a user can input a date and the program will output the day it is for that date. I am getting several errors message and I can not figure out where they are in the code.
#include <iostream>
using namespace std;
int get_date(int, int, int); // function declaration
int calc_year(int the_year);
int main()
{
int m, day, year, our_day; //month, day and year
cout<< "\nEnter any date as three sets of numbers.\n";
cout<< "(month, day, year). Example: 7 29 1971\n";
cout<<"Entering invalid dates will exit the program.\n";
cout<<"Enter date: ";
cin>>m>>day>>year; //input date
while((m != 13)&(day !=32)&(year != 0000)) //Invalid dates exit the loop
{
our_day = get_date(m, day, year);
//Passes the three values to get_date function
//Turns a numberical month into a named month when printed
switch(m)
{
case 1:
cout <<"January "<<end1;
break;
case 2:
cout <<"February "<<end1;
break;
case 3:
cout <<"March "<<end1;
break;
case 4:
cout <<"April "<<end1;
break;
case 5:
cout <<"May "<<end1;
break;
case 6:
cout <<"June "<<end1;
break;
case 7:
cout <<"July "<<end1;
break;
case 8:
cout <<"August "<<end1;
break;
case 9:
cout <<"September "<<end1;
break;
case 10:
cout <<"October "<<end1;
break;
case 11:
cout <<"November "<<end1;
break;
case 12:
cout <<"December "<<end1;
break;
}
cout<<" "<<end1;
case 1:
cout <<"Tuesday\n"<<end1;
break;
case 2:
cout <<"Wednesday\n"<<end1;
break;
case 3:
cout <<"Thursday\n"<<end1;
break;
case 4:
cout <<"Friday\n"<<end1;
break;
case 5:
cout <<"Saturday\n"<<end1;
break;
case 6:
cout <<"Sunday\n"<<end1;
break;
}
cout<<"\n\nEnter date: ";
cin>>m>>day>>year;
}
}
get_date(m, day, year); //function call
//get_date function
int get_date(int the_m, int the_day, int the_year)
{
//values for months of the year
int jan = 0, febr = 31, mar = 59, apr = 90,
may = 120, june = 151, july = 181, aug = 212,
sept = 243, octo = 273, nov = 304, dec = 334;
int the_month, the_date; //Variables used in calculations
if(3 > the_m)
{
if(2 == the_m)
{
the_date = febr + the_day;
}
else{
if(1 == the_m)
{
the_date = jan + the_day;
}
}
}
else
{
switch(the_m)
{
case 3: the_month = mar; break;
case 4: the_month = apr; break;
case 5: the_month = may; break;
case 6: the_month = june; break;
case 7: the_month = july; break;
case 8: the_month = aug; break;
case 9: the_month = sept; break;
case 10: the_month = octo; break;
case 11: the_month = nov; break;
case 12: the_month = dec; break;
}
if((0 == the_year%4) &! (0 == the_year%100))
{
the_date = the_day + (the_month + 1);
}
else
{
if(0 == the_year%400)
{
the_date = the_day + (the_month + 1);
}
else
{
the_date = the_day + the_month;
}
}
}
int first_day;//declares int
first_day = calc_year(the_year); //passing the_year to the new function, and assigning the return value to first_day
int this_day; //declaration for calculation.
this_day = the_date + first_day; //add the return value(count_day) to the_date and assign the sum to this_day.
//While () loop counts backwards by decrementing until it reaches the day
while(this_day >= 7)
{
this_day = this_day - 7;
}
this_day = this_day - 1; //Make the day before Monday (0 - 1) be Sunday
if(this_day == -1)
{
this_day = 6;
}
return this_day;
return 0;
}
//calc_year function
int calc_year(int the_year)
{
int count_day = 0; //start on Monday
//1900 started on a Monday, so don't enter the loop
for(int i = 1901; i <= the_year; i++)
{
count_day++; //day of the week.
if(count_day >= 7)
{
count_day = count_day - 7;
}
//reset at the end of each week
if((0 == ((i-1)%4)) &! (0 == ((i-1)%100)))
{
count_day = count_day + 1; //adjust for leapyear
}
else
{
if(0 == ((i-1)%400))
{
count_day = count_day + 1;
}
}
}
if(count_day == 7) //Make the day after Sunday (6 + 1) become Monday
{
count_day = 0;
}
return count_day;
}
errors are:
line 36 end1 undeclared identifier
line 75 illegal case
line 78 illegal case
line 81 illegal case
line 84 illegal case
line 87 illegal case
line 90 illegal case
line 98 main function should return a value
line 102 3 syntax error's missing ";" before }