C++ 未完成循环的嵌套for循环
当我运行程序的这一部分时,唯一有效的循环是涉及“week”变量的最后一个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:
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”,它运行得非常好!