c++ - Program is asking for input three times the first time, then twice when it shouldn't and ends prematurely -


my code seems asking numbers 3 times first time, twice when shouldn't , prematurely ending. can't seem figure out why.

little backstory: august, june, july 30 days (ignore july 31st) of weather. use '0' june, '1' july, , '2' august. 's' sunny 'r' rainy , 'c' cloudy. store in 2 dimensional array , display user in format.

this what's happening

enter image description here

and bigger picture

enter image description here

it goes through list #30 twice put @ end

the snippet of code believe affecting

// 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 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 weather july, ignoring 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 weather 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 days of weather 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 days of weather 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 days of weather 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;             }         }     } } 

i'm not sure i'm doing wrong appreciated. in advance

well without going through code in detail, see 2 errors right off bat:

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

these should if(x==1) , if(x==2)


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -