Ask coding questions

← Back to all posts
How to
jnrob900 (0)

after compiling ./dpsm 5 10 I try to get an output with 5 columns and 10 rows but I only get 1 row 1 column.

Comments
hotnewtop
DynamicSquid (5016)

You need a nested for loop to display 10 rows in display_states.

for (int i = 0; i < 10; ++i) { // add something like this
  for(phil = 0; phil < room->num_phils; phil++) {
      switch(room->phil_state[phil]) {
      case THINKING: printf("%-10s", "THINKING"); break;
      case HUNGRY: printf("%-10s", "HUNGRY"); break;
      case EATING: printf("%-10s", "EATING"); break;
      default: printf("%-10s", "CONFUSED");
      }
    }
   printf("\n"); // add newline for every row
}
DynamicSquid (5016)

You can also use a .replit file like the one I have here. Basically the .replit file runs a custom command every time your press the Run button