这个C++程序编译通不过,不知道出了什么问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 19:21:36
要求用结构体来做,输入年月日,算出是该年的第几天.
#include<iostream>
using namespace std;
struct Date
{int year;
int month;
int day;
};
int main()
{Date str1;
int i,j=0,k[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"请输入年,月,日:"<<endl;
cin>>str1.year>>str1.month>>str1.day;
while(str1.year<1)
{cout<<"无效的年份,请重新输入:"<<endl;
cin>>str1.year;
}
while(str1.month>12||str1.month<1)
{cout<<"无效的月份,请重新输入:"<<endl;
cin>>str1.month;
}
while(str1.day<1||str1.day>31)
{cout<<"无效的天,请重新输入:"<<endl;
cin>>str1.day;
}
cout<<"你输入的日期为:"<<str1.year<<"年"<<str1.month<<"月"<<str1.day<<"日."<<endl;
for(i=1;i<str1.month;i++)
{j+=k[i];}
j+=str1.day;

#include<iostream>

using namespace std;

struct Date
{
int year;
int month;
int day;
};

int main()
{
Date str1;
int i,j=0,k[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"请输入年,月,日:"<<endl;
cin>>str1.year>>str1.month>>str1.day;
while(str1.year<1)
{
cout<<"无效的年份,请重新输入:"<<endl;
cin>>str1.year;
}

while(str1.month>12||str1.month<1)
{
cout<<"无效的月份,请重新输入:"<<endl;
cin>>str1.month;
}

while(str1.day<1||str1.day>31)
{
cout<<"无效的天,请重新输入:"<<endl;
cin>>str1.day;
}

cout<<"你输入的日期为:"<<str1.year<<"年"<<str1.month<<"月"<<str1.day<<"日."<<endl;
f