繁体   English   中英

我不确定为什么“计数器”变量没有以我希望的方式响应

[英]I'm unsure exactly why the 'counter' variable isn't responding in the way I would like it to

请耐心等待,因为我对 C++ 和一般编码非常陌生。这是我第二次或第三次使用 arrays。 这是有问题的代码:

#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,但事实并非如此,因此什么也不做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM