Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未完成循环的嵌套for循环_C++_Loops_Cin - Fatal编程技术网

C++ 未完成循环的嵌套for循环

C++ 未完成循环的嵌套for循环,c++,loops,cin,C++,Loops,Cin,当我运行程序的这一部分时,唯一有效的循环是涉及“week”变量的最后一个for循环 cout << "Enter Building: "; cin >> building; cout << "\n"; cout << "Enter Room: "; cin >> room; cout << "\n"; cout << "Enter Numeric Month:

当我运行程序的这一部分时,唯一有效的循环是涉及“week”变量的最后一个for循环

cout << "Enter Building: ";
    cin >> building;
    cout << "\n";

    cout << "Enter Room: ";
    cin >> room;
    cout << "\n";

    cout << "Enter Numeric Month: ";
    cin >> monthIndex;
    monthIndex = monthIndex - 1;
    cout << "\n";

    cout << "Enter Week: ";
    cin >> week;
    cout << "\n";

    for (;building <= 30; building++)
    {
        for (;room <= 24; room++)
        {
            for (;monthIndex <= 11; monthIndex++)
            {
                for (;week <= 4; week++)
                {
                    cout << "Building: " << building << "\n";
                    cout << "Room: " << room << "\n";
                    cout << "Month: " << month[monthIndex] << "\n";
                    cout << "Week: " << week << "\n\n";
                }
            }
        }
    }
cout>建筑;
厕所;
cout-monthIndex;
monthIndex=monthIndex-1;
每周一次;

cout对于
循环,您需要在最后一个最内部的
末尾将
设置为
1

int
类型的变量吗?是。month[]是month Strings的数组。每个变量取决于用户输入。当周变为5时,下个月它将不再进入for循环,因为周的值已经是
5
。如何将周重置为1?@BrandonWiser:在最内层
for
循环
week=1的末尾应该可以。但问题还不止于此,根据您的要求,您可能需要执行类似于
monthIndex
room
的操作。我在“monthIndex”循环中最内层的“for”循环后放置了“week=1”,它运行得非常好!