血与酒狄拉夫怎么打:c++如何编写一个程序,判断今天是今年的第几天

来源:百度文库 编辑:中科新闻网 时间:2024/05/14 15:37:30
如题

把算法搞定,然后做

代码如下:
#include <iostream.h>
void compute_number_of_days(int y,int m,int d,int &no_of_days)
{
no_of_days=0;
switch(m)
{
case 12:no_of_days+=30;
case 11:no_of_days+=31;
case 10:no_of_days+=30;
case 9:no_of_days+=31;
case 8:no_of_days+=31;
case 7:no_of_days+=30;
case 6:no_of_days+=31;
case 5:no_of_days+=30;
case 4:no_of_days+=31;
case 3:
if(((y%4)==0&&(y%100)!=0)||((y%100)==0&&(y%400)==0))
no_of_days+=29;
else
no_of_days+=28;
case 2:no_of_days+=31;
case 1:no_of_days+=d;
}
}

void main()
{
int year,month,day;
int numberOfDay;
char more='y';
while(more=='y')
{
cout<<"please input the date of the day:\n";
cin>>year>>month>>day;
compute_number_of_days(year,month,day,numberOfDay);
cout<<"It's the"<<numberOfDay<<"day of the year"<<endl;
cout<<"continue:y/n?\n";
cin>>more;
}
}