Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would I use this void function to calculate the percentage?
    text
    copied!<p>I am working with DNA strands, so an input string will look something like: ATGC (with the possible bases A, T, G, and C)</p> <p>I have to utilize this function: void updateGCCount(char s[], int * gc, int * at) to calculate the percentage of "GC" content in the input string.</p> <p>The function, updateGCCount, sweeps through the contents of the input string, s, and updates the "GC" and "AT" counts appropriately.</p> <p>What I don't understand is, if this function doesn't return anything, if it's void, then how do I use this to calculate the percentage of "GC" content? </p> <p>Here's my code for the updateGCCount function:</p> <pre><code>void updateGCCount(char s[], int * gc, int * at){ int i; for(i=0;i!='\0';i++){ if(s[i]=='G' || s[i]=='C'){ (*gc)++; /*Updated with the help of people who answered!*/ } if(s[i]=='A' || s[i]=='T'){ (*at)++; /*Updated with the help of people who answered!*/ } } } </code></pre> <p>And now here is my main function with the call to the above function (added this code on after receiving some help from the answers below):</p> <pre><code>int main(){ char s[400]; int gc, at; double percentage; scanf("%s", s); gc = 0; at = 0; updateGCCount(s, &amp;gc, &amp;at); percentage = (gc * 100.0)/(strlen(s) - 1); printf("Sequence : %s\n", s); printf("GC-content: %.2f\n", percentage); return 0; } </code></pre> <p>PROBLEMS I'M HAVING! When I enter an input string of "ATCG", the percentage is 0 which isn't right and I can't figure out why it's giving me this problem! Help is greatly appreciated!</p> <p>Thanks!</p>
 

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