title: How to change 4 repeated digits in roman numerals converter?
body: <p>I am writing a program that converts an integer from 0 to 3999 into its roman numerals equivalent.</p>
  
  <p>Currently, my main function, which actually does the converting, works fine. It takes in a number, uses the roman numeral variables to make up the roman numeral array until the integer the user entered becomes 0:</p>
  
  <pre><code>int main(int argc, const char * argv[])
  {
      int num;
      char roman[10];
      int I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000;
  
      printf("Please input a number from 1 to 3999:\n");
      scanf("%d", &amp;num);
  
      do {
          for (int j = 0; j &lt; 10; j++) {
              if (num &gt;= M) {
                  num -= M;
                  roman[j] = 'M';
              }
              else if (num &gt;= D) {
                  num -= D;
                  roman[j] = 'D';
              }
              else if (num &gt;= C) {
                  num -= C;
                  roman[j] = 'C';
              }
              else if (num &gt;= L) {
                  num -= L;
                  roman[j] = 'L';
              }
              else if (num &gt;= X) {
                  num -= X;
                  roman[j] = 'X';
              }
              else if (num &gt;= V) {
                  num -= V;
                  roman[j] = 'V';
              }
              else if (num &gt;= I) {
                  num -= I;
                  roman[j] = 'I';
              }
          }
      } while (num != 0);
  
      // check(roman, 'X');
  
          printf("\nYour number in roman numerals is %s\n", roman);
  }
  </code></pre>
  
  <p>On the commented line is a separate function (called <code>check()</code>) that I wrote. This new function should ideally check for any letter that is repeated 4 times, and return true if there is such a case or false if not. It looks like this:</p>
  
  <pre><code>int check(char * numeralArray, char numeral)
  {
      int counter = 0;
      int size = strlen(numeralArray);
  
      for (int i = 0; i &lt; size; i++) {
          if(numeralArray[i] == numeral)     // check for each iteration if numeral is in numeralArray[i]
              counter++;     // if it is then counter increases by 1
          else
              counter = 0;    // this resets the value to 0 if its not consecutive.
  
          if(counter == 4)    // this stops the loop when 4 consecutive letters have been found.
              break;
      }
  
      if(counter &gt;= 4)    // if counter is 4, it means 4 consecutive letters have been found
          return 1;   // true
      else
          return 0;   // false
  }
  </code></pre>
  
  <p>So the idea is that I would use the function and pass <code>roman</code> and <code>I</code> as arguments to <code>check()</code>, for example. It would then check if <code>I</code> comes up 4 times consecutively. If it does, the function returns true (represented by 1). In my main function, if the value returned from <code>check()</code> is 1 (true), then I would want to change these four consecutive values (e.g. <code>IIII</code>) into the appropriate value (e.g. <code>IV</code>).</p>
  
  <p>The problem is, it does not work as it should, the <code>check()</code> function always returns 0 (false), even when I type in a number like 14, where instead of <code>XIIII</code>, it should be <code>XIV</code>. So I don't know how to get my function to return true in this case and then what would I have to do in order to make the desired change to the array? Also, in my main function, do I necessarily need a for loop inside the do-while loop? Or can I get rid of the for loop and just increment through the array each time the do-while loop runs (like this <code>j++</code>)? </p>