C++ for循环不断循环

C++ for循环不断循环,c++,for-loop,C++,For Loop,所以我把这个程序放在一起,一年中每个月取4个值。我遇到的唯一问题是,在我输入了12月份的最后一个输入之后,循环将继续并开始到1月份。我忘了什么 #include <iostream> #include <iomanip> using namespace std; enum Month {January,February,March,April,May,June,July,August,September,October,November,December }; vo

所以我把这个程序放在一起,一年中每个月取4个值。我遇到的唯一问题是,在我输入了12月份的最后一个输入之后,循环将继续并开始到1月份。我忘了什么

#include <iostream>
#include <iomanip>

using namespace std;

enum Month {January,February,March,April,May,June,July,August,September,October,November,December };

void displayMonthName (Month );

struct Airport
{
int numLanded;
int numDeparted;
int mostLanded;
int leastLanded;    

};

int main ()
{
int count;
const int MAX = 12;
double total = 0.0;
double average;

Airport year[MAX];

Month months;


for (count = 0 ; count < MAX ; count++)
{
    for ( months = January; months <= December ; months= static_cast <Month>(months + 1))       
        {
            cout<< "Enter the number of planes landed in ";
            displayMonthName(months);
            cout<<"\t";
            cin>>year[count].numLanded;

            cout<< "Enter the number of planes that landed in ";
            displayMonthName(months);
            cout<<"\t";
            cin>>year[count].numDeparted;

            cout<< "Enter the greatest number of planes that landed on a single day in ";
            displayMonthName(months);
            cout<<"\t";
            cin>>year[count].mostLanded;

            cout<< "Enter the least number of planes that landed on a single day in ";
            displayMonthName(months);
            cout<<"\t";
            cin>>year[count].leastLanded;

            cout << endl;

        }
}
#包括
#包括
使用名称空间std;
枚举月{1月、2月、3月、4月、5月、6月、7月、8月、9月、10月、11月、12月};
无效显示月名(月);
结构机场
{
国际货币基金组织;
int numDeparted;
内特莫斯特兰;
国际租赁;
};
int main()
{
整数计数;
常数int MAX=12;
双倍合计=0.0;
双倍平均;
机场年[最高值];
月份;
用于(计数=0;计数<最大值;计数++)
{

对于(月=一月;月因为你的
for
循环是嵌套的,你基本上循环了
12*12=144次。外循环循环12次,每个月每1个外循环你循环12次。这可能不是有意的。

你似乎有两个for循环。代码需要在fa中循环12年ct我想这不是你想要的。我本想加上这个作为评论,但我不能(我的声誉太低了!).

尝试过。这只会使它完全忽略12月,继续到1月。是的,可能是重复的,但除此之外,你完全忘记了你刚才写的内容。
int x=1;
-为什么
x
等于
1
?使用
int
比使用
enum
更简单r个月。例如,
displayMonthName
函数将是一个由12个字符串组成的常量数组,由月索引选择,而不是此
switch case
。因此,如何使循环仅为1?使循环为1。
void displayMonthName(Month m)
{
switch (m)
{
    case January    : cout<< "January";
                        break;
    case February   : cout<< "February";
                        break;
    case March      : cout<< "March";
                        break;
    case April      : cout<< "April";
                        break;
    case May        : cout<< "May";
                        break;
    case June       : cout<< "June";
                        break;
    case July       : cout<< "July";
                        break;
    case August     : cout<< "August";
                        break;  
    case September  : cout<< "September";
                        break;
    case October    : cout<< "October";
                        break;
    case November   : cout<< "November";
                        break;
    case December   : cout<< "December";                
}
}