Counter help

Reply

Join Date: Jan 2008
Posts: 70
Reputation: andyg55 is an unknown quantity at this point 
Solved Threads: 0
andyg55 andyg55 is offline Offline
Junior Poster in Training

Counter help

 
0
  #1
Mar 27th, 2008
Hi guys,

I have an input file as below (it is a family tree):

1 0 0
2 0 0
3 0 0
4 1 2
5 1 2
6 0 0
7 3 4
8 5 6
9 7 8
10 7 8

where column 1 = individual number
column 2 = mother number
column 3 = father number

so for example, individual 7's mom is individual 3, and his father is individual 4.

A further 2 columns are added. The program places a 0 or 1 in there depending on probabilities I have set out myself. An example of the output is as follows:

1 0 0 0 1
2 0 0 1 1
3 0 0 1 0
4 1 2 0 1
5 1 2 0 1
6 0 0 0 0
7 3 4 0 0
8 5 6 1 0
9 7 8 0 0
10 7 8 0 0

What I want to do is set a counter on how many 00's there are, how many 01's there are, and how many 11's there are. So for the above example, it would say:

00 = 4
01 = 4
11 = 2

My code is as below.

  1. #include <fstream.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int i, j;
  6. int matrix[10000][5] = {0}; //Define a matrix with a maximum of 100 rows and 6 columns
  7. int counters[2][2] = {0}; // Define the genotype counter
  8. int repeats = 0;
  9. int norepeats;
  10. float p, q;
  11. float rand1, rand2, rand3, rand4;
  12. void SetSeed();
  13.  
  14. int main () {
  15.  
  16. FILE *output_file = fopen("output.txt", "w");
  17.  
  18. printf("Enter the frequency of allele A: ");
  19. scanf("%f", &p);
  20. printf("\n");
  21. printf("Frequency of allele A (p) is: %.3f\n", p); // States the frequency of the A allele
  22. q = 1 - p; // The value of q is 1 - (the probability entered for p)
  23.  
  24. printf("Frequency of allele B (q) is: %.3f\n", q); // States the frequency of the B allele
  25. printf("\n");
  26. printf("Please enter the desired number of repeats: ");
  27. scanf("%d", &norepeats); // Desired number of repeats of the program stored in 'norepeats'
  28. printf("\n");
  29.  
  30. while (repeats != norepeats){ // A while loop to loop the program 'norepeats' amount of times
  31.  
  32. const float RANGE = 1.0; // Random number generated is below 1
  33. SetSeed(); // Seed file for RNG set here
  34.  
  35. //Open the input file//
  36. ifstream inFile;
  37. inFile.open("input.txt"); // Genealogy input file opened
  38.  
  39. if (!inFile)
  40. {
  41. printf ("Unable to open input file"); // Error message reported if input.txt cannot be opened
  42. exit(1);
  43. }
  44.  
  45. //Read the input file into the array
  46. while (inFile >> matrix[i][0])
  47. {
  48. printf ("%d\t", matrix[i][0]);
  49. for (j = 1; j < 3; j++)
  50. {
  51. inFile >> matrix[i][j];
  52. printf ("%d\t", matrix[i][j]);
  53. }
  54.  
  55. int counter;
  56.  
  57. if (matrix[i][1] == 0 && matrix[i][2] == 0){ // If the individual is a founder:
  58.  
  59. rand1 = (float) rand() * RANGE / RAND_MAX; // Random number 1 generated
  60. rand2 = (float) rand() * RANGE / RAND_MAX; // Random number 2 generated
  61.  
  62. if (rand1 < p){ // Place a 0 allele down in column 4 if random number 1 is below the set p value
  63. matrix[i][3] = 0;
  64. }
  65. else{
  66. matrix[i][3] = 1; // Place a 1 allele down in column 4 if random number 1 is above the set p value
  67. }
  68. printf("\t%d", matrix[i][3]);
  69.  
  70.  
  71. if (rand2 < p){ // Place a 0 allele down in column 5 if random number 2 is below the set p value
  72. matrix[i][4] = 0;
  73. }
  74. else{ // Place a 1 allele down in column 5 if random number 2 is above the set p value
  75. matrix[i][4] = 1;
  76. }
  77. printf("\t%d", matrix[i][4]);
  78. }
  79.  
  80. else{
  81. int dad = matrix[i][1]; // 1 is "dad" column
  82. int mum = matrix[i][2]; // 2 is "mum" column
  83.  
  84. int dadRowIndex = dad - 1; // The row of the father is 'dad - 1' as the first row is set at zero
  85. int mumRowIndex = mum -1; // The row of the mother is 'mum - 1' as the first row is set at zero
  86.  
  87. for (counter = 1;counter <= 1;counter++){
  88. rand3 = (float) rand() * RANGE / RAND_MAX; // Random number 3 generated
  89. rand4 = (float) rand() * RANGE / RAND_MAX; // Random number 4 generated
  90. }
  91. if (rand3 < 0.5){ // If random number 3 is less than a half, receive allele stored in column 4 from dad
  92. matrix[i][3] = matrix[dadRowIndex][3];
  93. }
  94. else{ // If random number 3 is more than a half, receive allele stored in column 5 from dad
  95. matrix[i][3] = matrix[dadRowIndex][4];
  96. }
  97. printf("\t%d", matrix[i][3]);
  98.  
  99. if (rand4 < 0.5){ // If random number 4 is less than a half, receive allele stored in column 4 from mum
  100. matrix[i][4] = matrix[mumRowIndex][3];
  101. }
  102. else{ // If random number 4 is more than a half, receive allele stored in column 5 from mum
  103. matrix[i][4] = matrix[mumRowIndex][4];
  104. }
  105. printf("\t%d", matrix[i][4]);
  106. }
  107.  
  108. i++;
  109. printf ("\n");
  110. }
  111.  
  112. inFile.close (); // Close the infile
  113. printf("\n");
  114. repeats++; // End loop here
  115. }
  116.  
  117. fclose(output_file);
  118.  
  119. }
  120.  
  121. void SetSeed()
  122. {
  123.  
  124. // Determining the seed file
  125. FILE *seed_file;
  126. long int seed_value;
  127.  
  128. seed_file = fopen("seed.txt","r"); // Open seed file
  129. fscanf(seed_file,"%d",&seed_value); // Exctract seed from file
  130. fclose(seed_file); // Close seed file
  131. srand(seed_value); // Randomise seed value
  132. seed_file = fopen("seed.txt","w"); // Create temporary output
  133. fprintf(seed_file,"%d",rand()); // Print random number to output
  134. fclose(seed_file); // Close temporary seed output file
  135. }

Any ideas guys?
Last edited by andyg55; Mar 27th, 2008 at 1:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 70
Reputation: andyg55 is an unknown quantity at this point 
Solved Threads: 0
andyg55 andyg55 is offline Offline
Junior Poster in Training

Re: Counter help

 
0
  #2
Mar 27th, 2008
ok guys... i attempted a counter of my own accord. Code as follows:

  1. #include <fstream.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int i, j;
  6. int matrix[10000][5] = {0}; //Define a matrix with a maximum of 100 rows and 6 columns
  7. int counters[2][2] = {0}; // Define the genotype counter
  8. int repeats = 0;
  9. int norepeats;
  10. float p, q;
  11. float rand1, rand2, rand3, rand4;
  12. void SetSeed();
  13.  
  14. int main () {
  15.  
  16. FILE *output_file = fopen("output.txt", "w");
  17.  
  18. printf("Enter the frequency of allele A: ");
  19. scanf("%f", &p);
  20. printf("\n");
  21. printf("Frequency of allele A (p) is: %.3f\n", p); // States the frequency of the A allele
  22. q = 1 - p; // The value of q is 1 - (the probability entered for p)
  23.  
  24. printf("Frequency of allele B (q) is: %.3f\n", q); // States the frequency of the B allele
  25. printf("\n");
  26. printf("Please enter the desired number of repeats: ");
  27. scanf("%d", &norepeats); // Desired number of repeats of the program stored in 'norepeats'
  28. printf("\n");
  29.  
  30. while (repeats != norepeats){ // A while loop to loop the program 'norepeats' amount of times
  31.  
  32. const float RANGE = 1.0; // Random number generated is below 1
  33. SetSeed(); // Seed file for RNG set here
  34.  
  35. //Open the input file//
  36. ifstream inFile;
  37. inFile.open("input.txt"); // Genealogy input file opened
  38.  
  39. if (!inFile)
  40. {
  41. printf ("Unable to open input file"); // Error message reported if input.txt cannot be opened
  42. exit(1);
  43. }
  44.  
  45. //Read the input file into the array
  46. while (inFile >> matrix[i][0])
  47. {
  48. printf ("%d\t", matrix[i][0]);
  49. for (j = 1; j < 3; j++)
  50. {
  51. inFile >> matrix[i][j];
  52. printf ("%d\t", matrix[i][j]);
  53. }
  54.  
  55. int counter;
  56.  
  57. if (matrix[i][1] == 0 && matrix[i][2] == 0){ // If the individual is a founder:
  58.  
  59. rand1 = (float) rand() * RANGE / RAND_MAX; // Random number 1 generated
  60. rand2 = (float) rand() * RANGE / RAND_MAX; // Random number 2 generated
  61.  
  62. if (rand1 < p){ // Place a 0 allele down in column 4 if random number 1 is below the set p value
  63. matrix[i][3] = 0;
  64. }
  65. else{
  66. matrix[i][3] = 1; // Place a 1 allele down in column 4 if random number 1 is above the set p value
  67. }
  68. printf("\t%d", matrix[i][3]);
  69.  
  70.  
  71. if (rand2 < p){ // Place a 0 allele down in column 5 if random number 2 is below the set p value
  72. matrix[i][4] = 0;
  73. }
  74. else{ // Place a 1 allele down in column 5 if random number 2 is above the set p value
  75. matrix[i][4] = 1;
  76. }
  77. printf("\t%d", matrix[i][4]);
  78. }
  79.  
  80. else{
  81. int dad = matrix[i][1]; // 1 is "dad" column
  82. int mum = matrix[i][2]; // 2 is "mum" column
  83.  
  84. int dadRowIndex = dad - 1; // The row of the father is 'dad - 1' as the first row is set at zero
  85. int mumRowIndex = mum -1; // The row of the mother is 'mum - 1' as the first row is set at zero
  86.  
  87. for (counter = 1;counter <= 1;counter++){
  88. rand3 = (float) rand() * RANGE / RAND_MAX; // Random number 3 generated
  89. rand4 = (float) rand() * RANGE / RAND_MAX; // Random number 4 generated
  90. }
  91. if (rand3 < 0.5){ // If random number 3 is less than a half, receive allele stored in column 4 from dad
  92. matrix[i][3] = matrix[dadRowIndex][3];
  93. }
  94. else{ // If random number 3 is more than a half, receive allele stored in column 5 from dad
  95. matrix[i][3] = matrix[dadRowIndex][4];
  96. }
  97. printf("\t%d", matrix[i][3]);
  98.  
  99. if (rand4 < 0.5){ // If random number 4 is less than a half, receive allele stored in column 4 from mum
  100. matrix[i][4] = matrix[mumRowIndex][3];
  101. }
  102. else{ // If random number 4 is more than a half, receive allele stored in column 5 from mum
  103. matrix[i][4] = matrix[mumRowIndex][4];
  104. }
  105. printf("\t%d", matrix[i][4]);
  106. }
  107.  
  108. i++;
  109. printf ("\n");
  110. }
  111.  
  112. inFile.close (); // Close the infile
  113.  
  114. for(i = 0; i < 10; i++) // Set the counter for the genotypes
  115. {
  116. if (matrix[i][3]==0 && matrix[i][4] ==0) // If alleles AA, increase counter [0][0] by 1
  117. {
  118. counters[0][0]++;
  119. }
  120.  
  121. else
  122. if (matrix[i][3]==0 && matrix[i][4] ==1 || matrix[i][3]==1 && matrix[i][4] ==0) // If allele is heterozygous, increase counter [0][1] by 1
  123. {
  124. counters[0][1]++;
  125. }
  126.  
  127. else
  128. if (matrix[i][3]==1 && matrix[i][4] ==1) // If alleles BB, increase counter [1][1] by 1
  129. {
  130. counters[1][1]++;
  131. }
  132. }
  133.  
  134. printf("\n");
  135. printf("Cumulative genotype totals:\n");
  136. printf("AA: %d\n", counters[0][0]); // Print total number of AA individuals
  137. printf("AB: %d\n", counters[0][1]); // Print total number of heterozygotes
  138. printf("BB: %d\n", counters[1][1]); // Print total number of BB individuals
  139. printf("\n");
  140. printf("\n");
  141. repeats++; // End loop here
  142. }
  143.  
  144. fclose(output_file);
  145.  
  146. }
  147.  
  148. void SetSeed()
  149. {
  150.  
  151. // Determining the seed file
  152. FILE *seed_file;
  153. long int seed_value;
  154.  
  155. seed_file = fopen("seed.txt","r"); // Open seed file
  156. fscanf(seed_file,"%d",&seed_value); // Exctract seed from file
  157. fclose(seed_file); // Close seed file
  158. srand(seed_value); // Randomise seed value
  159. seed_file = fopen("seed.txt","w"); // Create temporary output
  160. fprintf(seed_file,"%d",rand()); // Print random number to output
  161. fclose(seed_file); // Close temporary seed output file
  162. }

But the problem is, sometimes the counter works properly, and sometimes it doesn't.

I think it might have something to do with the number of repeats i do.

Does anyone see what I'm doing wrong?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,670
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 192
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Counter help

 
0
  #3
Mar 27th, 2008
You are missing counting the 1-0 combination.

Your main matrix defiition does not agree with your comment about it:
  1. int matrix[10000][5] = {0}; //Define a matrix with a maximum of 100 rows and 6 columns
is really 10,000 rows by 5 columns.

This is one of the problems with excess comments - they get out of sync as you modify a program. Comments should not state what is obvious from the code. Good variable names make many comments unnecessary.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 70
Reputation: andyg55 is an unknown quantity at this point 
Solved Threads: 0
andyg55 andyg55 is offline Offline
Junior Poster in Training

Re: Counter help

 
0
  #4
Mar 27th, 2008
Ok, well forgetting that comment (I have to excess comment to submit it to my markers, they're really strict on it)...

I'm not missing the 1-0 count. It is there if you look again.

The counting is weird. It seems to double itself sometimes, when really the numbers havn't doubled at all. Other times it gives obsurd answers that are huge etc.

Something is majorly wrong?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,670
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 192
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Counter help

 
0
  #5
Mar 27th, 2008
OK, I didn't see the 10 01 combined test.

Can you give a sample of the data and the resulting counts? Assuming the data is read and stored correctly, the counting block looks good.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,671
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Counter help

 
0
  #6
Mar 27th, 2008
First thing I'd try is to make intent of this statement perferctly clear by adding additional ():

if (matrix[i][3]==0 && matrix[i][4] ==1 || matrix[i][3]==1 && matrix[i][4] ==0)

like this:
  1. if ((matrix[i][3]==0 && matrix[i][4] ==1) ||
  2. (matrix[i][3]==1 && matrix[i][4] ==0))

If that didn't work I'd try to localize the problem by starting to comment out sections of the code until I came up with the section that seemed to cause the problem OR I'd print out baseline values of counters after initialization to be sure they were intialized correctly and then add output statements whereever the value is changed to be sure the values are changed appropriately.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,761
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 492
Featured Poster
VernonDozier VernonDozier is online now Online
Senior Poster

Re: Counter help

 
0
  #7
Mar 27th, 2008
I don't see where the counters array is being used. Can you point to the line number?
  1. #include <fstream.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int i, j;
  6. int matrix[10000][5] = {0}; //Define a matrix with a maximum of 100 rows and 6 columns
  7. int counters[2][2] = {0}; // Define the genotype counter
  8. int repeats = 0;
  9. int norepeats;
  10. float p, q;
  11. float rand1, rand2, rand3, rand4;
  12. void SetSeed();
  13.  
  14. int main () {
  15.  
  16. FILE *output_file = fopen("output.txt", "w");
  17.  
  18. printf("Enter the frequency of allele A: ");
  19. scanf("%f", &p);
  20. printf("\n");
  21. printf("Frequency of allele A (p) is: %.3f\n", p); // States the frequency of the A allele
  22. q = 1 - p; // The value of q is 1 - (the probability entered for p)
  23.  
  24. printf("Frequency of allele B (q) is: %.3f\n", q); // States the frequency of the B allele
  25. printf("\n");
  26. printf("Please enter the desired number of repeats: ");
  27. scanf("%d", &norepeats); // Desired number of repeats of the program stored in 'norepeats'
  28. printf("\n");
  29.  
  30. while (repeats != norepeats){ // A while loop to loop the program 'norepeats' amount of times
  31.  
  32. const float RANGE = 1.0; // Random number generated is below 1
  33. SetSeed(); // Seed file for RNG set here
  34.  
  35. //Open the input file//
  36. ifstream inFile;
  37. inFile.open("input.txt"); // Genealogy input file opened
  38.  
  39. if (!inFile)
  40. {
  41. printf ("Unable to open input file"); // Error message reported if input.txt cannot be opened
  42. exit(1);
  43. }
  44.  
  45. //Read the input file into the array
  46. while (inFile >> matrix[i][0])
  47. {
  48. printf ("%d\t", matrix[i][0]);
  49. for (j = 1; j < 3; j++)
  50. {
  51. inFile >> matrix[i][j];
  52. printf ("%d\t", matrix[i][j]);
  53. }
  54.  
  55. int counter;
  56.  
  57. if (matrix[i][1] == 0 && matrix[i][2] == 0){ // If the individual is a founder:
  58.  
  59. rand1 = (float) rand() * RANGE / RAND_MAX; // Random number 1 generated
  60. rand2 = (float) rand() * RANGE / RAND_MAX; // Random number 2 generated
  61.  
  62. if (rand1 < p){ // Place a 0 allele down in column 4 if random number 1 is below the set p value
  63. matrix[i][3] = 0;
  64. }
  65. else{
  66. matrix[i][3] = 1; // Place a 1 allele down in column 4 if random number 1 is above the set p value
  67. }
  68. printf("\t%d", matrix[i][3]);
  69.  
  70.  
  71. if (rand2 < p){ // Place a 0 allele down in column 5 if random number 2 is below the set p value
  72. matrix[i][4] = 0;
  73. }
  74. else{ // Place a 1 allele down in column 5 if random number 2 is above the set p value
  75. matrix[i][4] = 1;
  76. }
  77. printf("\t%d", matrix[i][4]);
  78. }
  79.  
  80. else{
  81. int dad = matrix[i][1]; // 1 is "dad" column
  82. int mum = matrix[i][2]; // 2 is "mum" column
  83.  
  84. int dadRowIndex = dad - 1; // The row of the father is 'dad - 1' as the first row is set at zero
  85. int mumRowIndex = mum -1; // The row of the mother is 'mum - 1' as the first row is set at zero
  86.  
  87. for (counter = 1;counter <= 1;counter++){
  88. rand3 = (float) rand() * RANGE / RAND_MAX; // Random number 3 generated
  89. rand4 = (float) rand() * RANGE / RAND_MAX; // Random number 4 generated
  90. }
  91. if (rand3 < 0.5){ // If random number 3 is less than a half, receive allele stored in column 4 from dad
  92. matrix[i][3] = matrix[dadRowIndex][3];
  93. }
  94. else{ // If random number 3 is more than a half, receive allele stored in column 5 from dad
  95. matrix[i][3] = matrix[dadRowIndex][4];
  96. }
  97. printf("\t%d", matrix[i][3]);
  98.  
  99. if (rand4 < 0.5){ // If random number 4 is less than a half, receive allele stored in column 4 from mum
  100. matrix[i][4] = matrix[mumRowIndex][3];
  101. }
  102. else{ // If random number 4 is more than a half, receive allele stored in column 5 from mum
  103. matrix[i][4] = matrix[mumRowIndex][4];
  104. }
  105. printf("\t%d", matrix[i][4]);
  106. }
  107.  
  108. i++;
  109. printf ("\n");
  110. }
  111.  
  112. inFile.close (); // Close the infile
  113. printf("\n");
  114. repeats++; // End loop here
  115. }
  116.  
  117. fclose(output_file);
  118.  
  119. }
  120.  
  121. void SetSeed()
  122. {
  123.  
  124. // Determining the seed file
  125. FILE *seed_file;
  126. long int seed_value;
  127.  
  128. seed_file = fopen("seed.txt","r"); // Open seed file
  129. fscanf(seed_file,"%d",&seed_value); // Exctract seed from file
  130. fclose(seed_file); // Close seed file
  131. srand(seed_value); // Randomise seed value
  132. seed_file = fopen("seed.txt","w"); // Create temporary output
  133. fprintf(seed_file,"%d",rand()); // Print random number to output
  134. fclose(seed_file); // Close temporary seed output file
  135. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 70
Reputation: andyg55 is an unknown quantity at this point 
Solved Threads: 0
andyg55 andyg55 is offline Offline
Junior Poster in Training

Re: Counter help

 
0
  #8
Mar 27th, 2008
Hi. I tried that but it still didn't work. An example of the output:

  1. Desired number of repeats = 3
  2.  
  3. 1 0 0 0 1
  4. 2 0 0 1 1
  5. 3 0 0 0 1
  6. 4 1 2 1 1
  7. 5 1 2 1 1
  8. 6 0 0 1 0
  9. 7 3 4 0 1
  10. 8 5 6 1 1
  11. 9 7 8 1 1
  12. 10 7 8 0 1
  13.  
  14. Cumulative totals:
  15. 00 = 0
  16. 10 = 5
  17. 11 = 5
  18.  
  19.  
  20. 1 0 0 0 0
  21. 2 0 0 1 0
  22. 3 0 0 0 1
  23. 4 1 2 1 1
  24. 5 1 2 1 1
  25. 6 0 0 0 1
  26. 7 3 4 1 1
  27. 8 5 6 1 1
  28. 9 7 8 1 1
  29. 10 7 8 1 1
  30.  
  31. Cumulative totals:
  32. 00 = 0
  33. 10 = 10
  34. 11 = 10
  35.  
  36.  
  37. 1 0 0 0 0
  38. 2 0 0 0 1
  39. 3 0 0 0 1
  40. 4 1 2 1 1
  41. 5 1 2 0 1
  42. 6 0 0 1 1
  43. 7 3 4 0 1
  44. 8 5 6 1 0
  45. 9 7 8 0 1
  46. 10 7 8 1 1
  47.  
  48. Cumulative totals:
  49. 00 = 0
  50. 10 = 15
  51. 11 = 15

Any ideas?
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Counter help

 
0
  #9
Mar 27th, 2008
  1. int sum = matrix[i][3] + matrix[i][4] ;
  2. if( sum == 2 ) ++counters[1][1] ;
  3. else if( sum == 1 ) ++counters[0][1] ;
  4. else ++counters[0][0] ;
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 70
Reputation: andyg55 is an unknown quantity at this point 
Solved Threads: 0
andyg55 andyg55 is offline Offline
Junior Poster in Training

Re: Counter help

 
0
  #10
Mar 27th, 2008
Hate to do this vernon but...

counters array???
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC