Counting the number of times a loop has run

This is a discussion on Counting the number of times a loop has run within the C Programming forums, part of the General Programming Boards category; I need to know how many times the following loop was run and have no clue: ( I need to ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    9

    Counting the number of times a loop has run

    I need to know how many times the following loop was run and have no clue: ( I need to know how many "v"s I have calculated)

    Code:
    		
    for (i = 0; i <= D; ++i) //Counting up by one for duration/burnrate values
    {
    float m, v = vi, h = 500;  //Find t for h = 0.0, set as td
    	// Must initialize v to the initial velocity ( like v = 0)
    
    m = masschange(duration[i], burnrate[i], total);
    
    for (j = 0; j <= duration[i]; j = j + tstep)	// j keeps track of the amount of time each duration has run for
    
    {          		     				
     a = ((m*G) - (burnrate[i]*ve))/m;
    				
    v = v - (a*tstep);	// Like ++v, but with something else +'ing
          		 		
    printf("%.3f\n", v);
    fprintf(outFile, "%.3f\n", v);	// Calculates the nth velocity
    
    h = h - (v*tstep);
    printf("\t%.3f\n", h); //Check to see if the height is going to 0
    
    if (h <= 0) 		// Stops when h = 0.
    {
       return 1;
    }
    			
    }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > v = v - (a*tstep); // Like ++v, but with something else +'ing
    So increment something then, say
    numOfVsCalculated++;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with number counting program
    By Turtal in forum C Programming
    Replies: 11
    Last Post: 04-25-2009, 02:40 PM
  2. Number Guessing
    By blacknapalm in forum C Programming
    Replies: 2
    Last Post: 10-01-2008, 01:48 AM
  3. counting number of lines in my output file
    By zesty in forum C Programming
    Replies: 34
    Last Post: 12-25-2007, 08:15 PM
  4. Replies: 2
    Last Post: 12-02-2007, 04:40 AM
  5. Counting Number of days from year zero
    By wireless in forum C++ Programming
    Replies: 4
    Last Post: 06-16-2002, 07:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21