gpt4 book ai didi

c++ - 嵌套的 for 循环没有完成它们的循环

转载 作者:行者123 更新时间:2023-11-28 08:10:21 26 4
gpt4 key购买 nike

当我运行程序的这一部分时,唯一可以工作的循环是最后一个涉及“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";
}
}
}
}

示例输出:

按1打印所有票本

按 2 打印特定票簿

按3退出程序

2 菜单选择

进入大楼:26

进入房间:20

输入数字月份:8

输入星期:2

建筑:26房间:20月份:八月周:2

建筑:26房间:20月份:八月周:3

建筑:26房间:20月份:八月周:4

最佳答案

您需要在最后一个 for 循环结束时将 week 设置为 1

关于c++ - 嵌套的 for 循环没有完成它们的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9306002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com