user2387766
user2387766

Reputation:

How do I print my outputs into the form of a table?

This is what my output should look like:

enter image description here

Since it's a little hard to read, essentially, it's this diagram, we're basically just substituting the values we get for the function into the boxes:

enter image description here

NOTE: That the first box is NOT (1, 1), it is (1, 20).

I wrote some code for this but the output isn't in that table form, and I'm not sure how to get it into something that looks like that. And we have to do this for multiple functions but just so that it's easier for you to look at/work with, I'll just post up two of the functions that I have to do.

Here are the two functions:

enter image description here

And here's my code:

#include <stdio.h>
#include "grove.h"

int main() {
   int i, j;
   double soilqual, sunexp, irrexp, yield, qual, harvtime, plantcost, ppu,
      rev, fprofit, retinvest, annurev, fscore;

   printf("================ Soil Quality ================\n");
   for (j = 20; j >= 1; j--) {
      for (i = 1; i <= 20; i++) {
         soilqual = soilQuality(i, j);
         printf(".3%f\n", soilqual);
      }
      printf("\n");
   }
   printf("---------------------------------------------------------------            -----\n");
   printf("\n");
   printf("================ Sun Exposure ================\n");
   for (j = 20; j >= 1; j--) {
      for (i = 1; i <= 20; i++) {
         sunexp = sunExposure(i, j);
         printf(".3%f\n", sunexp);
      }
      printf("\n");
   }
   printf("---------------------------------------------------------------            -----\n");
   printf("\n");
}

Upvotes: 0

Views: 79

Answers (1)

Stram
Stram

Reputation: 826

I'm not sure I got what you want, but if you are trying to have a grid that has 20 column and 20 row try substituting the \n in the printf in the inner loop with a space:

  printf("================ Soil Quality ================\n");
   for (j = 20; j >= 1; j--) {
      for (i = 1; i <= 20; i++) {
         soilqual = soilQuality(i, j);
         printf(".3%f ", soilqual); <<-- here
      }
      printf("\n");
   }

Upvotes: 1

Related Questions