2015-10-15 54 views
2

我的代碼似乎是第一次請求我的數字三次,然後兩次,當它不應該過早地結尾。我似乎無法弄清楚爲什麼。程序第一次要求輸入三次,然後兩次不應該結束並且提前結束

小背景故事:8月,6月,7月得30天(不計7月31日)天氣。六月使用'0',七月使用'1',八月使用'2'。 'S'表示Sunny'R'表示Rainy,'C'表示多雲。存儲在2維數組中並以格式顯示回用戶。

這是發生了什麼

enter image description here

,然後大局觀

enter image description here

它穿過列表#30次,然後不正是我放在句末

我認爲這段代碼會影響它

// char 'R' = 82 
// char 'C' = 67 
// char 'S' = 83 
bool flag = true; 
char temp; 
int calendar[3][30]; 
for(int x = 0; x <= 2; x++) 
{ 
    for(int y = 0; y <= 29; y++) 
    { 
     if(x==0) 
     { 
      if(flag) 
      { 
       cout << "\nPlease enter weather for June"; 
       flag = false; 
      } 
      cout << "\nDay #" << y + 1 << " "; 
      cin >> temp; 
      temp = toupper(temp); 
      calendar[x][y] = temp; 
      if(y == 29) 
       flag = true; 
     } 
     if(x=1) 
     { 
      if(flag) 
      { 
       cout << "\nPlease enter the weather for July, ignoring the 31st"; 
       flag = false; 
      } 
      cout << "\nDay #" << y + 1 << " "; 
      cin >> temp; 
      temp = toupper(temp); 
      calendar[x][y] = temp; 
      if(y == 29) 
       flag = true; 
     } 
     if(x=2) 
     { 
      if(flag) 
      { 
       cout << "\nPlease enter the weather for August"; 
       flag = false; 
      } 
      cout << "\nDay #" << y + 1 << " "; 
      cin >> temp; 
      temp = toupper(temp); 
      calendar[x][y] = temp; 
      if(y == 29) 
       flag = true; 
     } 

    } 
} 
flag = false; 
for(int n = 0; n <= 2; n++) 
{ 
    for(int m = 0; m <= 29; m++) 
    { 
     if(n == 0) 
     { 
      if(flag) 
      { 
       cout << "\nIn June the days of weather are as follows "; 
       flag = false; 
      } 
      cout << "\n Day #" << m << ": "; 
      if(calendar[n][m] == 82) 
      { 
       cout << "Rainy"; 
      } 
      if(calendar[n][m] == 83) 
      { 
       cout << "Sunny"; 
      } 
      if(calendar[n][m] == 67) 
      { 
       cout << "Cloudy"; 
      } 
      if(m == 29) 
      { 
       flag = true; 
      } 

     } 
     if(n == 1) 
     { 
      if(flag) 
      { 
       cout << "\nIn July the days of weather are as follows "; 
       flag = false; 
      } 
      cout << "\n Day #" << m << ": "; 
      if(calendar[n][m] == 82) 
      { 
       cout << "Rainy"; 
      } 
      if(calendar[n][m] == 83) 
      { 
       cout << "Sunny"; 
      } 
      if(calendar[n][m] == 67) 
      { 
       cout << "Cloudy"; 
      } 
      if(m == 29) 
      { 
       flag = true; 
      } 

     } 
     if(n == 2) 
     { 
      if(flag) 
      { 
       cout << "\nIn August the days of weather are as follows "; 
       flag = false; 
      } 
      cout << "\n Day #" << m << ": "; 
      if(calendar[n][m] == 82) 
      { 
       cout << "Rainy"; 
      } 
      if(calendar[n][m] == 83) 
      { 
       cout << "Sunny"; 
      } 
      if(calendar[n][m] == 67) 
      { 
       cout << "Cloudy"; 
      } 
      if(m == 29) 
      { 
       flag = true; 
      } 
     } 
    } 
} 

我不知道我在做什麼錯,所以任何幫助表示讚賞。在此先感謝

回答

1

良好,沒有經過詳細所有的代碼去,我看到了蝙蝠的兩個錯誤:

if(x=1)if(x=2)

這些應該是if(x==1)if(x==2)

+0

緊,該固定一切。好人。謝謝 – RyanJohnTyler

相關問題