我不确定为什么"计数器"变量没有以我想要的方式响应



请耐心等待,因为我是C++和编码的新手。到目前为止,这是我第二次或第三次使用数组。这是有问题的代码:

#include <iostream>
using namespace std;
int main() 
{
int day,month,counter;
int year[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"Input a day of a month";
cin>>day;
cout<<"Input the month of the year";
cin>>month;
for(int x=0;x>12;x++)
{
cin>>year[x];
counter+=year[x];
}

cout<<"The Date is " <<day<<" / "<<month<<" and, "<<endl;
cout<<"The number of days until this date is reached again is:"<<counter<<endl;
}

我试图让代码显示用户估算的日期,以及再次到达该日期的天数。但是计数器变量仅显示0。我确信这是我尚未发现的某种形式的逻辑错误。

您的循环for(int x=0;x>12;x++)将x设置为0,然后检查它是否大于12(事实并非如此(,从而结束不执行任何操作。

相关内容

最新更新