We are supposed to write a program which asks for the month, date, and yr and then outputs the day of that date.

input:

Month:   7  // This is July
Day: 4
Year: 1776

output:

July 4, 1776  was on a Thursday

Formula:

day = (r + [2.6m - .2] - 2c + d + [c/4.0] +[d/4.0] ) % 7


[x] denotes the greatest integer less than or equal to x (look in cmath).
c  = first two digits of the year. (If the year is 1898, c = 18).
d  = the last two digits of the year. (If the  year is 1998, d = 98).
r  = the day of the month (If the date is May 23, 1998, r = 23).
m  = the month.   March is considered month 1, April is  2, May is 3...February is month 12.

this is my code [c++]:

#include<iostream>
#include<cmath>
using namespace std;


char Date(int c, int d, int r, int m);


int main()
{


int month, day, yr, yr1, yr2;


cout<<"month:"<<endl;
cin>>month;


cout<<"day:"<<endl;
cin>>day;


cout<<"year:"<<endl;
cin>>yr;


yr1=yr/100;
yr2=yr%100;


cout<<month<<" "<<day<<" "<<yr<<" "<<Date(yr1, yr2, day, month);
}


char Date(int c, int d, int r, int m)
{


char result;
result=ceil(r+(2.6*m-.2)-2*c+d+(c/4.0)+(d/4.0))%7;


switch(result)
{
case 1: cout<<" was on a sun";
break;
case 2: cout<<" was on a mon";
break;
case 3: cout<<" was on a tues";
break;
case 4: cout<<" was on a wed";
break;
case 5: cout<<" was on a thurs";
break;
case 6: cout<<" was on a fri";
break;
case 7: cout<<" was on a sat";
break;
default: cout<<"invalid";


return result;
}
}



//when i compile it, i get the error "'%' illegal, left operand, has type 'double""

try this

char result;
result=(int)(ceil(r+(2.6*m-.2)-2*c+d+(c/4.0)+(d/4.0)))%7;

K.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.