choosing certain cells to display in 2D arrays
Sep 15, 2015 at 11:57pm UTC
Hello everyone,
This is what the program is supposed to do. If the user chooses option 1 or 2 (main menu)the program is supposed to display only the occupied offices. If they choose option 3, than it should only display the empty offices.
When I choose 3, the program displays nothing, which it is should display everything because the entire array is originally set to empty. Any help would be greatly appreciated. Thank you.
here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
char chooseAndDisplayChoice(int amount, char option, officeBuilding buildingArray)
{
//variables
if (option == '1' || option == '2' )
{
if (amount == 0) //if all offices are empty, output error message
{ //return to main menu
cout << "ERROR! All offices are empty" << endl;
return 5;
}
else
{
cout << "Occupied offices:" <<endl;
displayOccupiedOffices(buildingArray);
}
}
else
{
cout << "Empty offices:" <<endl;
displayEmptyOffices(buildingArray);
}
return option;
}
//*************************************************************************************
char convertColumn(int column)
{
//variables
switch (column)
{
case 0:
column = 'A' ;
break ;
case 1:
column = 'B' ;
break ;
case 2:
column = 'C' ;
break ;
case 3:
column = 'D' ;
break ;
case 4:
column = 'E' ;
break ;
case 5:
column = 'F' ;
break ;
case 6:
column = 'G' ;
break ;
default :
column = 'H' ;
}
return column;
}
//*********************************************************************************
void displayEmptyOffices(officeBuilding buildingArray)
{
//variables
int row, col;
for (int row = FLOOR_ROW -1; row > 0; row--) //for loop to display office floor and column letter
{
for (int col = 0; col < OFFICE_COL; col++)
{
if (buildingArray[row][col] = EMPTY) //if array is EMPTY display row and letter
cout << setw(7) << row << convertColumn(col) << setw(7);
else //if not EMPTY display nothing
cout << setw(7) << " " << setw(7);
}
cout << endl;
}
}
//***********************************************************************************
void displayOccupiedOffices(officeBuilding buildingArray)
{
//variables
int row, col;
for (int row = FLOOR_ROW -1; row > 0; row--) //for loop to display office floor and column letter
{
for (int col = 0; col < OFFICE_COL; col++)
{
if (buildingArray[row][col] = EMPTY) //if not EMPTY display nothing
cout << setw(7) << " " << setw(7);
else //if occupied display row and letter
cout << setw(7) << row << convertColumn(col) << setw(7);
}
cout << endl;
}
}
Sep 16, 2015 at 2:42am UTC
line 69: == EMPTY
Sep 16, 2015 at 3:07am UTC
And the same for line 87: == EMPTY
Sep 16, 2015 at 3:10am UTC
Going by the comment shouldn't line 87 be != EMPTY
?
Sep 16, 2015 at 3:25am UTC
Yeah, you're right kemort. I stopped reading the line after seeing the single equals, mainly because the remark was so far away from the line of code. Poor excuse from me, for sure.
Sep 16, 2015 at 4:09am UTC
Cheers! :)
Sep 18, 2015 at 5:30pm UTC
Thanks everyone for your comments. Much appreciated.
Topic archived. No new replies allowed.