Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to increment counters based on a printed array
    primarykey
    data
    text
    <p>I managed to developed a simple board of 5x5 using random numbers and array. Big achievement for someone like me! :)</p> <p>Now I have to increment the counters depending on the frequency of the numbers.</p> <p>If the value within 0-49 is printed..then nCounter++ If the value within 50-75 is printed..then pCounter++ something like that.</p> <p>The problem is that I don't know how to <strong>increase the counters based on the printed board</strong>.</p> <p>Here is the code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; int main() { //Initialize Variables int randomNumber; int rows; int columns; int hdCounter =0; int hCounter = 0; int cCounter = 0; int pCounter = 0; int nCounter = 0; //Declare board size int board[5][5]; //size of board is 5 x 5 //Create the random number generator seed srand(time(NULL)); //Assign the random numbers from 1 - 25 into variable randomNumber //Create the rows for the board for ( rows = 1; rows &lt;= 5 ; rows++ ) { //Create the colimns for the board for ( columns = 1; columns &lt;= 5 ; columns++ ) { //Assign variable randomNumber into variable board randomNumber = rand() %100 + 1; board[rows][columns] = randomNumber; //print the board printf("%d\t", board[rows][columns]); //calculate the frequency of numbers on the printed board if (randomNumber &gt;= 85 &amp;&amp; randomNumber &lt;= 100 ) hdCounter++; else if ( randomNumber &gt;= 75 ) hCounter++; else if ( randomNumber &gt;= 65 ) cCounter++; else if ( randomNumber &gt;= 50 ) pCounter++; else if ( randomNumber &gt;= 1 ) nCounter++; else continue; } //Newline after the end of 5th column. printf("\n\n"); } printf( "N \t P \t C \t H \t HD\n\n" ); printf("%d \t %d \t %d \t %d \t %d \t", nCounter, pCounter, cCounter, hCounter, hdCounter); }//end main </code></pre> <p>I tried replacing <code>randomNumber</code> in the if-statement with <code>board[rows][columns]</code> but I seem to get the same undesired results.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload